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!

Deleting Records from 100+ tables

User_4LC0GSep 2 2021

Hello Experts,
Oracle DB version : Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production
We have a requirement to delete data from 100+ tables.
We have currently implemented this requirement using DELETE statements on each of the 100+ tables.
After deleting the records from all the tables , we issue a COMMIT.
Below is a Pseudo Code for each table :

 DECLARE
     CURSOR c1 is
      SELECT 'x' from tab1 where id = :b1 for update nowait; --acquire row lock

BEGIN

OPEN c1;

DELETE FROM tab1 where id = :b1;

CLOSE c1;

.
.
.
.
.
.
.
.
.
.
.
COMMIT;

EXCEPTION
..............
END;
/

Column ID is indexed.
The current implementation performs poorly. It takes around 1 hour to delete 1000 id's from the 100+ tables in a certain order due to integrity constraints.
Our target is to delete 10,000 id's from all tables.
In order to improve performance we have thought of using BULK COLLECT and FORALL in order to DELETE records.
However, I have the following queries :
1. Could you please suggest how to acquire row level locks on a table while using collections.
2. Could you please suggest how to issue a COMMIT after every 1000 records in order to ensure that I don't run out of the available in the UNDO tablespace.

I would be grateful if you could also suggest a better appraoch apart from the one I mentioned above.
Thank You.

Comments

The rule you have described will work if "the order total" is an attribute on the Line Items entity, which is the parent of the PartsDetails relationship. If you are getting the error message described you should do the following:

1. check that the relationship text for Line ITems --> PartDetails is "the PartDetails"

2. check that you have a number or currency attribute with the text "the order total" on the Line Items entity.

3. If you are rely on an automatically created attribute, you should change the attribute to "the Line Items order total". If you include the text of an entity in an attribute, the automatically created attribute will be placed in the correct entity, and then the InstanceSum statement will be correct for the attribute.

Cheers

Frank

ParthibHW

Hi Frank, It is not working. If I flatten the structure keep 1 entity (line item details) under global, InstanceSum works fine. For nested datamodel relationship, instanceSum not working.

PathhibHW,

This is almost certainly becuase the rule is trying to create the attribute "the order total" on the global entity, in this case it cannot sum across all line items, all part details.

Have a look at my suggestions 2. and 3. make either of those changes and your rule should work.

Cheers

Frank

ParthibHW

Hi Frank, Thanks a lot. It is working now. Can you please share the scenario for "Reasoning across entity instances" ForScope statement. Thanks.

Answer

Glad to hear you got it working.

Due to quirks of our rule parser, you can't sum across a deep relationship structure in one rule using scope operations. However with a few itermediate attributes it becomes pretty simple.

To sum all the PartDetails of a quote. I would use the following two rules:

the line item's total = instancesum(the PartDetails, the PartDetails ItemPrice)

the quote's total = instancesum(the line items, the line item's total)

You have to sum the totals across one relationship at a time.

Cheers

Frank

Marked as Answer by ParthibHW · Sep 27 2020
1 - 5

Post Details

Added on Sep 2 2021
5 comments
549 views