On the road again

Провести процедуру очисти БД Oracle можно подключившись к базе с помощью sqlplus и запустив скрипт.

declare
cursor c1 is
select 'alter table ' || owner || '.' || table_name || ' drop constraint ' || constraint_name constraint_to_drop
from all_constraints
where owner not in ('DBSNMP','NSA','OUTLN','PSA','SYS','SYSTEM','WMSYS', 'PUBLIC')
and constraint_type = 'R'
order by owner, constraint_name;

cursor c2 is
select 'drop ' || object_type || ' ' || owner || '.' || object_name as object_name
from all_objects
where object_type not in ('INDEX', 'LOB', 'TRIGGER')
and owner not in ('DBSNMP','NSA','OUTLN','PSA','SYS','SYSTEM','WMSYS', 'PUBLIC')
order by owner, object_name;
begin
for c1_rec in c1 loop
dbms_output.put_line(c1_rec.constraint_to_drop);
execute immediate(c1_rec.constraint_to_drop);
end loop;

for c2_rec in c2 loop
dbms_output.put_line(c2_rec.object_name);
execute immediate(c2_rec.object_name);
end loop;

end;
/

Это классический вариант очистки БД Oracle.

 

Add comment