且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL查询和存储过程未产生期望的结果

更新时间:2023-01-07 14:27:41

尝试将函数标记为 NOT确定性,看看是否有帮助。默认情况下,所有功能都是确定性的,这意味着数据库服务器可以在某些情况下缓存结果。以此方式进行标记将强制服务器每次重新评估查询/功能。

Try marking your function as NOT DETERMINISTIC and see if that helps. By default, all functions are deterministic, which means the database server can cache the result under certain circumstances. Marking it this way will force the server to re-evaluate the query/function each time.

CREATE FUNCTION read_and_increment()
RETURNS NUMERIC(20,0)
NOT DETERMINISTIC
BEGIN
    DECLARE @number_just_read NUMERIC(20,0);

      SELECT number INTO @number_just_read
        FROM _DMigNumbers;

      UPDATE _DMigNumbers
         SET number = number + 1;
   RETURN @number_just_read;
End