Here is a small script that will help you delete orphaned child records when the parent keys are deleted.Useful when you are in development environment.

I have used a parent table called P and a child table called C.First we disable the refrential integrity constraint on C .Then delete the records in P. now run our script which produces the script to delete the records from the refrenced tables (child tables) run it and after that we can enable the constraint.

select * from p;
1
2
3

select * from c;
1 1
1 2
1 3
2 1
2 2
2 3
3 3
3 1
3 2

9 rows selected.

delete from p where p_x=1

delete from p where p_x=1
*
ERROR at line 1:
ORA-02292: integrity constraint (SCOTT.FK_C_CX) violated - child record found