触发器
create sequence seqrole start with 4
create or replace trigger truserrolsinsert
before insert
on userroles
for each row
begin
if inserting then
select seqrole.nextval into :new.id from dual;(
将序列seqrole的下一个值 赋给新插入数据的id
)
end if;
end;
insert into userroles values(0,'xx')
select * from userroles
2,
create or replace trigger truserrolsupdateordelete
after delete or update
on userroles
for each row
begin
if :old.id=3 then
dbms_output.put_line('管理员不能改也不能删除');
rollback;
end if;
end;
delete from userroles where id>=4
update userroles set name=name;
3,instead of 执行删除更新操作时触发,代替delete or update on viewUsers
for each row
create view viewUsers2
as
select * from users;
select * from viewUsers2
delete from viewUsers where id=3
create or replace trigger trviewUsersupdateordelete
instead of delete or update
on viewUsers
for each row
begin
dbms_output.put_line('要删除的用户是:'||:old.name);
end;
delete from viewUsers
select * from viewUsers
posted on 2015-10-27 16:31 kebizhanmushi 阅读(111) 评论(0) 编辑 收藏 举报