我想创建一个触发器,它将确保除非我们不禁用触发器,否则不能从表中删除任何记录。 请把宝贵的时间用于解决这个问题。
答案 0 :(得分:0)
您可以使用如下。只要在表上触发delete语句,此trigger
就会引发错误。
SQL> CREATE OR REPLACE TRIGGER DONT_DELETE
2 BEFORE DELETE
3 ON TAB1
4 FOR EACH ROW
5 BEGIN
6 RAISE_APPLICATION_ERROR (-20000,'No delete allowed');
7 END;
8 /
Trigger created.
SQL> select * from tab1;
COL
----------
1
2
3
SQL> delete from tab1 where col = 1;
delete from tab1 where col = 1
*
ERROR at line 1:
ORA-20000: No delete allowed
ORA-06512: at "SCOTT.DONT_DELETE", line 2
ORA-04088: error during execution of trigger 'SCOTT.DONT_DELETE'