我正在尝试遍历表格中的trip_numbers列表。每当我尝试使用FOR循环时,我都会收到以下错误:
错误:在“cur1”之后发现意外的标记“CURSOR”。预期的代币可能包括:“加入”。 SQLSTATE-42601
CREATE TRIGGER SCHEMA.UPDATE_OP_CODE_2
AFTER UPDATE OF USER1 ON TLORDER
REFERENCING NEW AS N
FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
DECLARE mTRIP_NUMBER INTEGER; --
FOR v AS cur1 CURSOR FOR (SELECT TRIP_NUMBER FROM ITRIPTLO WHERE
DETAIL_LINE_ID = N.DETAIL_LINE_ID)--
DO
SET mTRIP_NUMBER = cur1.TRIP_NUMBER;
IF (mTRIP_NUMBER IS NOT NULL AND mTRIP_NUMBER != 0) THEN
CALL DF_SAVELEGINTERSECTION(mTRIP_NUMBER, 'True'); --
CALL OPTIMIZE_CARRIER(mTRIP_NUMBER); --
CALL DF_CALCULATETRIPTOTALS(mTRIP_NUMBER, 'True'); --
END IF; --
END FOR;
END
我可以不在触发器内使用FOR循环/光标吗?
答案 0 :(得分:1)
删除“cur1 CURSOR FOR”。触发器的“内联复合”不支持此功能。
CREATE TRIGGER SCHEMA.UPDATE_OP_CODE_2
AFTER UPDATE OF USER1 ON TLORDER
REFERENCING NEW AS N
FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
DECLARE mTRIP_NUMBER INTEGER; --
FOR v AS (SELECT TRIP_NUMBER FROM ITRIPTLO WHERE DETAIL_LINE_ID = N.DETAIL_LINE_ID)--
DO
SET mTRIP_NUMBER = TRIP_NUMBER;--
IF (mTRIP_NUMBER IS NOT NULL AND mTRIP_NUMBER != 0) THEN
CALL DF_SAVELEGINTERSECTION(mTRIP_NUMBER, 'True'); --
CALL OPTIMIZE_CARRIER(mTRIP_NUMBER); --
CALL DF_CALCULATETRIPTOTALS(mTRIP_NUMBER, 'True'); --
END IF; --
END FOR;--
END