一旦执行 UPDATE 语句,“WHERE CURRENT OF”子句将在行上放置排他锁。“WHERE CURRENT OF”子句将指向游标的最近获取的行。
我们可以通过以下方式使用“WHERE CURRENT OF”更新游标中的行。
光标定义。
EXEC SQL DECLARE ORDER_CUR CURSOR FOR SELECT ORDER_ID, TRANSACTION_ID FROM ORDERS WHERE ORDER_DATE = ‘2020-07-28’ END-EXEC
打开光标
EXEC SQL OPEN ORDER_CUR END-EXEC
FETCH 游标和更新行
SET WF-END-CURSOR-N TO TRUE PERFORM UNTIL WF-END-CURSOR-Y EXEC SQL FETCH ORDER_CUR INTO :ORDER-ID, :TRANSACTION-ID END-EXEC IF TRANSACTION-ID NOT = SPACES EXEC SQL UPDATE ORDERS SET IS_PAID = ‘YES’ WHERE CURRENT OF ORDER_CUR END-EXEC ELSE CONTINUE END-IF END-PERFORM