我想創建一個BEFORE INSERT
觸發,將檢查字段的輸入值,而在另一行具有相同的字段替換它,如果該字段爲空。但是,當我將CALL
語句添加到我的觸發器時,將返回錯誤「The trigger "ORGSTRUCT.CSTCNTR_IN" is defined with an unsupported triggered SQL statement
」。我查看了文檔,發現在BEFORE(首先製作存儲過程的部分原因)中不支持遊標,但即使我從存儲過程中刪除了遊標聲明,該調用仍會生成相同的錯誤。BEFORE INSERT觸發器和存儲過程調用(DB2 LUW 9.5)
觸發:
CREATE TRIGGER orgstruct.cstcntr_IN
NO CASCADE
BEFORE INSERT ON orgstruct.tOrgs
REFERENCING NEW AS r
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
DECLARE prnt_temp BIGINT;
DECLARE cstcntr_temp CHAR(11);
SET prnt_temp = r.prnt;
SET cstcntr_temp = r.cstcntr;
CALL orgstruct.trspGetPrntCstCntr(prnt_temp,cstcntr_temp);
SET r.cstcntr = cstcntr_temp;
END
存儲過程:
CREATE PROCEDURE orgstruct.trspGetPrntCstCntr (
IN p_prnt BIGINT,
OUT p_cstcntr CHAR(11)
)
SPECIFIC trGetPrntCstCntr
BEGIN
IF p_prnt IS NULL THEN
RETURN;
END IF;
BEGIN
DECLARE c1 CURSOR
FOR
SELECT cstcntr
FROM orgstruct.tOrgs
WHERE id = p_prnt
FOR READ ONLY;
OPEN c1;
FETCH FROM c1 INTO p_cstcntr;
CLOSE c1;
END;
END
根據該文件,CALL
被允許在BEFORE
觸發,所以我不明白是什麼問題。