发生错误,自动回滚的。 1 create or replace trigger tri_ins_x
2 before insert on x
3 for each row
4 declare
5 num int;
6 begin
7 select count(*) into num from x where a=:new.a and ch=:new.ch;
8 if (num>=1)
9 then
10 RAISE_APPLICATION_ERROR (
11 num=> -20107,
12 msg=> 'Duplicate customer or order ID');
13 end if;
14* end;
SQL> /触发器已创建SQL> select * from x; A CH
---------- ----
343
3 er
1 ww
23 t345
353 bnq已选择6行。SQL> insert into x values(1,'ww');
insert into x values(1,'ww')
*
ERROR 位于第 1 行:
ORA-20107: Duplicate customer or order ID
ORA-06512: 在"SCOTT.TRI_INS_X", line 7
ORA-04088: 触发器 'SCOTT.TRI_INS_X' 执行过程中出错
2 before insert on x
3 for each row
4 declare
5 num int;
6 begin
7 select count(*) into num from x where a=:new.a and ch=:new.ch;
8 if (num>=1)
9 then
10 RAISE_APPLICATION_ERROR (
11 num=> -20107,
12 msg=> 'Duplicate customer or order ID');
13 end if;
14* end;
SQL> /触发器已创建SQL> select * from x; A CH
---------- ----
343
3 er
1 ww
23 t345
353 bnq已选择6行。SQL> insert into x values(1,'ww');
insert into x values(1,'ww')
*
ERROR 位于第 1 行:
ORA-20107: Duplicate customer or order ID
ORA-06512: 在"SCOTT.TRI_INS_X", line 7
ORA-04088: 触发器 'SCOTT.TRI_INS_X' 执行过程中出错
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货