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!

I want to drop tables based on their references i.e FK and PK order. How to select all tables?

Albert ChaoSep 13 2021 — edited Sep 13 2021
set serveroutput on;
declare
lv_str varchar2(1000);
begin
for c in(select distinct a.table_name as table_name, b.table_name as parent_table_name
from
all_constraints a
left outer join all_constraints b on a.r_constraint_name = b.constraint_name and a.owner = b.owner) loop
lv_str :='DROP TABLE '||c.table_name;
--lv_str :='DROP TABLE '||c.parent_table_name;


dbms_output.put_line(lv_str);
end loop;
end;

Will this work?

This post has been answered by KayK on Sep 13 2021
Jump to Answer
Comments
Post Details
Added on Sep 13 2021
19 comments
1,364 views