分类: Oracle
2008-10-15 15:43:50
SQL> select * from v$version;
BANNER
---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production SQL> create table t1(dml varchar2(20));
表已创建。
SQL> create table t2(x number(1));
表已创建。
SQL> create trigger tri_t2
2 before insert or update or delete on t2 for each row 3 begin 4 if inserting then 5 insert into t1 values('insert'); 6 elsif updating then 7 insert into t1 values('update'); 8 elsif deleting then 9 insert into t1 values('delete'); 10 end if; 11 end; 12 / 触发器已创建
SQL> insert into t2 values(1);
已创建 1 行。
SQL> select *from t1;
DML
-------------------- insert SQL> update t2 set x = 2;
已更新 1 行。
SQL> select *from t1;
DML
-------------------- insert update SQL> delete t2;
已删除1行。
SQL> select * from t1;
DML
-------------------- insert update delete 已选择3行。
SQL> |
SQL> truncate table t1;
表已截掉。
SQL> truncate table t2;
表已截掉。
SQL> insert into t2 select rownum from user_objects where rownum <
6;
已创建5行。
SQL> select * from t1;
DML
-------------------- insert insert insert insert insert SQL> update t2 set x = x + 1;
已更新5行。
SQL> select * from t1;
DML
-------------------- insert insert insert insert insert update update update update update 已选择10行。
SQL> delete t2;
已删除5行。
SQL> select * from t1;
DML
-------------------- insert insert insert insert insert update update update update update delete delete delete delete delete 已选择15行。 |
SQL> truncate table t1;
表已截掉。
SQL> truncate table t2;
表已截掉。
SQL> create or replace trigger tri_t2
2 before insert or update or delete on t2 3 begin 4 if inserting then 5 insert into t1 values('insert'); 6 elsif updating then 7 insert into t1 values('update'); 8 elsif deleting then 9 insert into t1 values('delete'); 10 end if; 11 end; 12 / 触发器已创建
SQL> insert into t2 select rownum from user_objects where rownum <
6;
已创建5行。
SQL> select * from t1;
DML
-------------------- insert SQL> update t2 set x = x + 1;
已更新5行。
SQL> select * from t1;
DML
-------------------- insert update SQL> delete t2;
已删除5行。
SQL> select * from t1;
DML -------------------- insert update delete |