My Oracle scott schema contains table list like that
'prefix_A'
'prefix_B'
'prefix_C'
'A'
'B'
'C'
Now i want to drop list of tables ,containing table prefix like that 'Prefix_',But others table A ,B ,C will be remain same.
How it is possible ?
Thanks in Advance.
Use dynamic SQL driving off the data dictionary.
It's a good idea to be precise with the LIKE clause; using the
escape
keyword to ensure underscores aren't treated as wildcards. Alternatively usesubstr(table_name, 1, 7) = 'PREFIX_'
.Dropping the wrong table isn't a disaster provided you're working on 10g or later and the RECYCLE BIN is enabled, but it's still better not to. Obviously you wouldn't run code like this in Production, but you would use the principle to generate a script of drop statements.
The above code doesn't handle dependencies. If you have foreign keys referencing the prefixed tables and you want to force the dropping of the tables use this additional logic:
This drops the foreign key constraints but leaves the (formerly) dependent tables.
I used this to disable constraints, drop constraints and delete the tables.