在触发器内部,我试图遍历表上的所有列并将新值与旧值进行比较。这是我到目前为止所拥有的:
CREATE OR REPLACE TRIGGER "JOSH".TEST#UPD BEFORE
UPDATE ON "JOSH"."TEST_TRIGGER_TABLE" REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
declare
oldval varchar(2000);
newval varchar(2000);
begin
for row in (SELECT column_name from user_tab_columns where table_name='TEST_TRIGGER_TABLE') loop
execute immediate 'select :old.'||row.column_name||' from dual' into oldval;
execute immediate 'select :new.'||row.column_name||' from dual' into newval;
--Do something here with the old and new values
end loop;
end;
触发器编译,但是当触发器触发时,我得到:
ORA-01008: 并非所有变量都绑定
在第一次执行时立即执行,因为它期望:old
. :old
并且:new
已经被定义为触发器的一部分,但是执行立即似乎看不到这些变量。
有没有办法动态迭代触发器中的列值?