/* 同一表使用所有条件 Create or replace trigger t5 Before insert,delete,update on 表名 For each row //plsql块 */ /* 在触发器中,还有三个变量:都是boolean INSERTING 正在执行insert吗。 DELETING UPDATING */ select TABLE_NAME from USER_TABLES; select * from trigger_t2; desc trigger_t2; create or replace trigger t4 before INSERT OR UPDATE or delete on trigger_t2 FOR EACH ROW declare begin if inserting then dbms_output.put_line('写入'); elsif deleting then dbms_output.put_line('删除'); else dbms_output.put_line('更新'); end if; end; ---测试 set serveroutput on; insert into trigger_t2 values(1,'jk',23); delete from trigger_t2 where id=1; update trigger_t2 set name='kk'; --------------------------------------------------- --------------------------------------------------- --使用when语句设置条件 create or replace trigger t5 before INSERT on trigger_t2 FOR EACH ROW when (NEW.age<=18) declare begin DBMS_OUTPUT.PUT_LINE('大于20是:'||:NEW.age); RAISE_APPLICATION_ERROR(-20000, '年龄小于18不能参与'); end; set serveroutput on; INSERT INTO TRIGGER_T2 VALUES(4,'KK',22); /* --禁用trigger alter trigger t4 disable; alter trigger t4 enable; --修改名称 alter trigger t4 rename to t5; */
转载于:https://www.cnblogs.com/xiaweifeng/p/3681377.html