0
下面的代碼有什麼問題,有些可以幫助我解決它嗎?在oracle中使用合併語句觸發
CREATE OR REPLACE TRIGGER TEST_TRI
AFTER INSERT
ON TEST1
FOR EACH ROW WHEN (NEW.COL2 >= '01-MAY-16')
BEGIN
IF INSERTING
THEN
MERGE INTO TEST_HIST HIST
USING TEST1 T1
ON (T1.NEW.COL1=HIST.COL2)
WHEN MATCHED THEN
UPDATE SET
HIST.COL5=NEW.COL5
WHEN NOT MATCHED
THEN
INSERT INTO
VALUES (:NEW.COL1,:NEW.COL2,:NEW.COL3,:NEW.COL4,:NEW.COL5);
END IF;
END;
/
錯誤: 錯誤(4,3):PL/SQL:SQL語句忽略 錯誤(12,14):PL/SQL:ORA-00926:缺失值KEYWORD
感謝您的信息,我已經改變了下面的代碼,並得到新的錯誤。
CREATE OR REPLACE TRIGGER test_tri
after INSERT
ON test1
FOR EACH ROW WHEN (NEW.col5 >= '01-MAY-16')
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
IF INSERTING
THEN
MERGE INTO test_hist hist
USING test1 t1
ON (t1.PACKAGE_ID=hist.PACKAGE_ID)
WHEN MATCHED THEN
UPDATE SET
hist.col5=t1.col5
WHEN NOT MATCHED
THEN
INSERT (col1,col2, col3, col4, col5)
VALUES (:NEW.col1,:NEW.col2,:NEW.col3,:NEW.col4,:NEW.col5);
END IF;
COMMIT;
END;
/
雖然test1的表中插入記錄我得到以下錯誤 ORA-30926:無法獲得穩定的組行的源表
'當匹配時 更新集 HIST.COL5 =:NEW.COL5' - 您錯過了':' – Tatiana
您在插入語句中缺少列名稱列表。然後插入(col1,col2 ...)值(:new.col1,:new.col2 ...) – Rene
感謝您的更新,請參閱上面的問題(已更改) –