更新行时游标变量是否更新?

Is the cursor variable updated when updating a row?

下面的代码(存储过程体)中,游标字段的值是否在UPDATE后自动更新?如果不是,关闭/打开命令是否足够?

我没有找到包含此内容的任何描述,所有内容中都只有 FOR SELECT 游标。

DECLARE VARIABLE FCU_VALIDATE TYPE OF COLUMN FCU_CTRL.FCU_VAL_WHEN_IMP;

DECLARE FCU_DOC_MSTR CURSOR FOR
    (SELECT * FROM FCU_DOC_MSTR
     WHERE FCU_DOC_APN = :APNUMBER
       AND FCU_DOC_ID  = :DOCID);
BEGIN
     OPEN FCU_DOC_MSTR;
     
     FETCH FIRST FROM FCU_DOC_MSTR;
     -- CHECK CONTROL FILE SETTINGS
     
     FCU_VALIDATE = COALESCE((SELECT FCU_VAL_WHEN_IMP FROM FCU_CTRL
                              WHERE FCU_INDEX1 = 1), FALSE);
     
     IF (FCU_VALIDATE = TRUE) THEN
     BEGIN
          -- IF EXIST INVALID ITEM DETAIL LINE, SET DOCUMENT STATUS TO INVALID
          IF ((SELECT COUNT(*) FROM FCU_ITEM_DET
               WHERE FCU_ITEM_APN     = :FCU_DOC_MSTR.FCU_DOC_APN
                 AND FCU_ITEM_DOC_ID  = :FCU_DOC_MSTR.FCU_DOC_ID 
                 AND FCU_ITEM_STATUS != '0') > 0) THEN
              UPDATE FCU_DOC_MSTR
                 SET FCU_DOC_STATUS = '90'
              WHERE CURRENT OF FCU_DOC_MSTR;  
     END

     -- CHECK DOCUMENT STATUS IS IMPORTED AND NO ERROR EXIST SET STATUS TO IMPORTED
     IF (FCU_DOC_MSTR.FCU_DOC_STATUS = '99') THEN
        UPDATE FCU_DOC_MSTR
           SET FCU_DOC_STATUS = '0'
        WHERE CURRENT OF FCU_DOC_MSTR;   
      
     IF (FCU_VALIDATE = TRUE) THEN
     BEGIN   
         IF (FCU_DOC_MSTR.FCU_DOC_STATUS = '0') THEN
            UPDATE FCU_DOC_MSTR
               SET FCU_DOC_STATUS = '1'
            WHERE CURRENT OF FCU_DOC_MSTR;     
         
         -- UPDATE FILE STATUS   
         IF ((SELECT COUNT(*) FROM FCU_DOC_MSTR
              WHERE FCU_DOC_FILE_ID = :FCU_DOC_MSTR.FCU_DOC_FILE_ID
                AND FCU_DOC_STATUS != '1') > 0) THEN
             UPDATE FCU_FILE_MSTR
                SET FCU_FILE_STATUS = '90'
             WHERE FCU_FILE_ID = :FCU_DOC_MSTR.FCU_DOC_FILE_ID;
         ELSE
             UPDATE FCU_FILE_MSTR
                SET FCU_FILE_STATUS = '1'
             WHERE FCU_FILE_ID = :FCU_DOC_MSTR.FCU_DOC_FILE_ID;
     END   
      
     CLOSE FCU_DOC_MSTR;
END

如果更新是通过游标完成的(使用UPDATE ... WHERE CURRENT OF _cursor_name_),那么当前行的游标记录变量也会更新。

请参阅 this fiddle 进行演示。

这在 Firebird 3.0 发行说明中没有记录,但在 doc/sql.extensions/README.cursor_variables.txt included with your Firebird installation. This is also been documented in the Firebird 3.0 Language Reference, under FETCH:

中有记录

Reading from a cursor variable returns the current field values. This means that an UPDATE statement (with a WHERE CURRENT OF clause) will update not only the table, but also the fields in the cursor variable for subsequent reads. Executing a DELETE statement (with a WHERE CURRENT OF clause) will set all fields in the cursor variable to NULL for subsequent reads