PL/SQL to perform FOREACH
jbriskinAug 28 2008 — edited Aug 29 2008I 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?