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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

PL/SQL to perform FOREACH

jbriskinAug 28 2008 — edited Aug 29 2008
I want to do something I think is pretty simple but I cannot figure out how to put it into an Oracle procedure.

I want to selct a set of tables based upon LIKE condition in the table name then delete from the table where the column name is the table name with an '_ID' added to the name and the column value is <> 0.

In PERL this would look a lot like the following...

create an array with all the table names \[assumes you already have a db connection\]
@myTables = (SELECT DISTINCT tname FROM tab WHERE tname LIKE 'someCondition');

foreach my $myTabName(@myTables)
{
print "EXECUTE IMMEDIATELY 'DELETE FROM ".$myTabName." WHERE ".$myTabName."_ID <> 0'; \n";
}

Now how would one do this is in a stored procedure?
This post has been answered by hpuelman on Aug 28 2008
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2008
Added on Aug 28 2008
21 comments
1,070 views