利用触发器做dml操作日志

ylg007 2004-04-16 11:37:16
想通触发器跟踪某字段值的变化。
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';

到底问题出在哪?请大家指点。

...全文
69 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ylg007 2004-04-18
  • 打赏
  • 举报
回复
问题已在www.itpub.com解决.
需要显示的授权.
grant select on sys.V_$SQLTEXT to user;

不过还是感谢包子的帮助.
ylg007 2004-04-17
  • 打赏
  • 举报
回复
DBA权限还不行吗?
ylg007 2004-04-17
  • 打赏
  • 举报
回复
没有权限创建触发器?
baojianjun 2004-04-17
  • 打赏
  • 举报
回复
無權限

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧