oracle - 变异,触发器/函数在使用触发器时可能看不到错误
问题描述
我有一个表 bugs_metadata,比如 create table bugs_metadata(REPORT_NAME varchar2(10), WHERE_CLAUSE varchar2(100)); 插入 bugs_metadata('test','29603754,29605708,29649865'); 在更新上表中的 WHERE_CLAUSE 列时,我在下面的触发器中收到“变异,触发器/函数可能看不到它”错误:
create or replace TRIGGER "c_b_c_b_update" AFTER
UPDATE ON bugs_metadata
FOR EACH ROW
BEGIN
CASE
WHEN UPDATING('WHERE_CLAUSE') THEN
IF :NEW.WHERE_CLAUSE is not null THEN
insert into bug_data(BUG_NUMBER,SUBJECT)
select rptno,SUBJECT
from rpthead
where rptno in (select regexp_substr(:NEW.WHERE_CLAUSE,'[^,]+',1,level) WHERE_CLAUSE
from bugs_metadata t2
connect by regexp_substr(:NEW.WHERE_CLAUSE,'[^,]+',1,level) is not null )
and rptno not in(select bug_number from bug_data);
END IF;
END CASE;
END;
你能告诉我这里有什么问题吗?
解决方案
DUAL
应该使用而不是bugs_metadata
. 这样做没有问题,因为您只是将一列拆分为行,因此无需使用实际表,因为值已经存在于:new.where_clause
.
看--> right here -->
线,它标志着地点。
create or replace trigger c_b_c_b_update
after update on bugs_metadata
for each row
begin
case
when updating('WHERE_CLAUSE') then
if :new.where_clause is not null then
insert into bug_data(bug_number, subject)
select rptno, subject
from rpthead
where rptno in (select regexp_substr(:new.where_clause, '[^,]+', 1, level)
--> right here --> from dual
connect by regexp_substr(:new.where_clause, '[^,]+', 1, level) is not null
)
and rptno not in (select bug_number
from bug_data
);
end if;
end case;
end;