ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle trigger语法小记(一)

oracle trigger语法小记(一)

原创 Linux操作系统 作者:wisdomone1 时间:2010-07-24 17:09:05 0 删除 编辑

SQL> update dept1 set dname='new accounting' where deptno=1;
update dept1 set dname='new accounting' where deptno=1
       *
ERROR at line 1:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "SCOTT.T_DEPT1", line 3

ORA-04088: error during execution of trigger 'SCOTT.T_DEPT1'


SQL>

 

####说明在触发器内部不能有commit或者rollback,触发器会自动提交的哟
SQL> create or replace trigger t_dept1
  2  after update of dname on dept1 for each row
  3  begin
  4  insert into dept1_audit values(:old.deptno,sysdate,:new.dname,:old.dname);
  5  end;
  6  /

Trigger created.

SQL> update dept1 set dname='new accounting' where deptno=1;

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from dept1_audit;###更新了表的某行记录后,触发器发生了作用,把变更记录的新老记录存储在此表中

    DEPTNO UP_DATE      NEW_DNAME                                                                                            OLD_DNAME
---------- ------------ ---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
         1 22-7月 -10   new accounting
        

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-668943/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12690159