利用触发器做dml操作日志
想通触发器跟踪某字段值的变化。
create or replace trigger "SCM".tb_spbasic_supcode
BEFORE update on scm.spbasic
for EACH row
declare
begin
if INSERTING then return; end if;
if DELETING then return; end if;
if UPDATING and (:new.supcode=:old.supcode) then return; end if;
if updating then
insert into spbasic_log (USERNAME,MACHINE,SID,SERIAL#,SUPCODE,LOGON_TIME,SQL_TEXT)
select username,machine,sid,serial#,old.supcode,logon_time,sql_text
from sys.V_$SESSION,sys.V_$SQLTEXT
where sql_address=address
and username='SCM';
end if;
exception
when OTHERS then raise;
end tb_spbasic_supcode;
系统提示:Compilation errors for TRIGGER SCM.TB_SPBASIC_SUPCODE
Error: PLS-00201: 必须说明标识符 'SYS.V_$SESSION'
Line: 15
Text: from sys.V_$SESSION,sys.V_$SQLTEXT
Error: PL/SQL: SQL Statement ignored
Line: 13
Text: insert into spbasic_log (USERNAME,MACHINE,SID,SERIAL#,SUPCODE,LOGON_TIME,SQL_TEXT)
下列语句可单独正常运行,到了触发器就有问题。
insert into spbasic_log (USERNAME,MACHINE,SID,SERIAL#,SUPCODE,LOGON_TIME,SQL_TEXT)
select username,machine,sid,serial#,‘000123’,logon_time,sql_text
from sys.V_$SESSION,sys.V_$SQLTEXT
where sql_address=address
and username='SCM';
到底问题出在哪?请大家指点。