时间:2021-07-01 10:21:17 帮助过:72人阅读
刚接触Oracle,新建了一个before delete的触发器,但老是报ldquo;警告: 创建的触发器带有编译错误rdquo;,最后发现是触发器里面
刚接触Oracle,,新建了一个before delete的触发器,但老是报“警告: 创建的触发器带有编译错误”,最后发现是触发器里面的语句没有写分号的原因。
下面帖出来,也供新手参考:
1.创建表:
create table test1(CardID number, Name NVARCHAR2(20), Sex NUMBER);
create table test2(CardID number, Name NVARCHAR2(20));
create table test3(CardID number, Name NVARCHAR2(20));
2.触发器--删除Test2中的记录时将其备份到Test3:
create or replace trigger Trig_Del_Backup
after delete
on test2
for each row
declare
--fdsfaf
begin
insert into test3 values(:old.cardid, :old.name);
end
;
/
3.触发器--删除Test2时同时删除Test1:
create or replace trigger Trig_Del
after delete
on test2
for each row
declare
--fdsfaf
begin
delete from test1 where CardID=:old.CardID and Name=:old.name;
end
;
/