Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cascade delete of self referencing tbl using triggers

223563Jun 4 2002
I'd like to implement a trigger on a self referencing table that'll cascade delete entries in that table. Consider the following example...

create table person
(name varcher2(40), id number, parent_id number);

A sample set of table records might look like...

name id parent_id
-----------------------
joe 1 NULL
mary 2 1
betty 3 9
bill 4 1
sally 5 2

If/when I go to delete 'joe' I'd like the trigger to delete mary and bill (because thier parent_id = joe's id) as well as sally (because her parent_id = mary's id and mary's parent_id is joe's id).

The closest I've come is....

create trigger cascade_del_person
before delete on person for each row
begin
delete from person where parent_id = :old.id;
end;

If errors out with an ORA_04091 telling me that the table is mutating.

Any suggestions?

Thanks
-dave

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2002
Added on Jun 4 2002
10 comments
1,677 views