插入后,我需要更新同一表中的一列。 INSERT已经编码,无法更改。因此,我们将使用TRIGGER方法来更新一列值。
create or replace TRIGGER "BLT_TRIGGER"
AFTER INSERT ON BLT_MAPPING
FOR EACH ROW
BEGIN
UPDATE BLT_MAPPING
SET FIELD_ID = (SELECT CASE WHEN CORR_TI = 'B' THEN '12345' ELSE '54321' END
AS INSTITUTION FROM BROKER CO,LOAN LO
WHERE LO.CORR_ID = CO.CORR_ID AND LO.LOAN_ID = loanid_in_BLT_MAPPING_table
whcih_got_inserted )
END;
我正在清除错误。我在触发器中犯了什么错误。
答案 0 :(得分:2)
您是否要更新刚插入的同一行?在这种情况下,您要使其成为BEFORE INSERT
触发器,并在将:NEW.fieldid
插入表之前对其进行更改。像这样:
create or replace TRIGGER "BLT_TRIGGER"
BEFORE INSERT ON BLT_MAPPING
FOR EACH ROW
l_new_fieldid number; -- Or whatever the correct datatype is
BEGIN
SELECT CASE WHEN CORR_TI = 'B' THEN '12345' ELSE '54321' END
INTO l_new_fieldid
FROM BROKER CO,LOAN LO
WHERE LO.CORR_ID = CO.CORR_ID
AND LO.LOAN_ID = :NEW.loanid;
:NEW.fieldid := l_new_fieldid;
END;
但这是次等的解决方案。触发器使您难以真正执行操作,并且在出现问题时很难调试。更好的解决方案是用您真正想做的事情来更正INSERT
语句。