|
Re: how to run delete trigger when truncating a table [message #28497 is a reply to message #28495] |
Thu, 25 December 2003 21:56 |
Srinivas
Messages: 138 Registered: June 2000
|
Senior Member |
|
|
CREATE TABLE x (a NUMBER)
CREATE TABLE y (b NUMBER)
Trigger on x if delete from x then truncate table y
CREATE OR REPLACE TRIGGER Example
BEFORE DELETE ON x
FOR EACH ROW
DECLARE
xyz VARCHAR2(100);
PRAGMA autonomous_transaction;
BEGIN
xyz:= 'truncate table y';
EXECUTE IMMEDIATE xyz;
END Example;
/
NOTE:- Truncate table will do a auto commit . you need to take care.
Delete from x;
Select * from y;
HTH
Srini
|
|
|
|
|
Re: Re: how to run delete trigger when truncating a table [message #28539 is a reply to message #28501] |
Tue, 30 December 2003 00:38 |
janno
Messages: 1 Registered: December 2003
|
Junior Member |
|
|
Well, actually Oracle also provides
(cant say exactly from which version since)
it's specific truncate-triggers :
create or replace TRIGGER prevent_trunc
before truncate on schema
WHEN (ora_dict_obj_name='YOUR_TABLE_NAME' AND ora_dict_obj_TYPE='TABLE')
Begin
RAISE_APPLICATION_ERROR(-20111, ' Truncate is not allowed .... table is protected !');
END;
and or course, add your own (in aforementioned WHEN-section) restrictions when necessary
|
|
|