With some very hard work and innovative thinking we came up with the procedures (can be easily clubbed into package) to delete the parent child relationship row with any number of levels.
Below code would find the child row of the parent row being deleted and delete it first , if the child row has its own child then that childs children are fetched and deleted so its basically a recursive algorithm
There are not many situations where you would want to use this. We had a customer mstr record to be deleted which had 20 levels of child records held tight by (ORA-02292: integrity constraint violated - child record found ) with their parent child constraints.
Since this only was a delete for 1 Master record we went ahead and used this script. If you have more than 20 levels Wise course would be to disable constraints and really think why you want to delete such master record.
Note of caution : BE CAREFUL using this on production environment.
The procedures create the insert statements along the line as it deletes the parent child rows , but its done in DBMS_OUTPUT so make sure you have that turned on if you want insert statement roll back plan to be created. You can of course be innovative and dump inserts in another table or use utl_file to write them elsewhere.
Usage : Find DEL_PARENT_CHILD On
2nd Last line is the call to main recursive delete.
1st Argument is TABLE NAME here (Order_Header_TBL)
2nd Argument is Where Clause PROCEDURE CAN DELETE ONLY 1 PARENT LINE AT A TIME.
MAKE SURE YOUR WHERE CLAUSE IS FETCHING ONLY 1 ROW.
If you want to delete multiple rows call it that many times in a lopp or whichever way you see fit.
QueryLight is a lightweight Oracle database client.
Please help us in betterment of the software by donating generously. Your encouragement and funds will keep the site going.
Donate Here on Paypal.
Subscribe to:
Post Comments (Atom)
AWS solution architect exam questions.
Before taking this let it be known that the questions are sourced from random sites using simple algorithms. The authenticity of questions a...
-
If we want to perform hierarchical queries we need to use connect by clause in our sql query. Hierarchical query is any query wherin yo...
-
If you have 3000 lines of code and a custom exception handler like when others. The ORA 06502 can be notoriously elusive to find. This er...
-
Starting from Oracle database release 10g you can have DML's succeed with partial data failures. How ? Default reaction of any bulk I...
No comments:
Post a Comment
Please leave your relevant comments and questions only.