Skip to main content

Command Palette

Search for a command to run...

Drop all objects from a schema

(without dropping the schema)

Updated
1 min readView as Markdown
Drop all objects from a schema
D

I ❤️ Oracle APEX

begin for cur_rec in (
  select
    object_name,
    object_type
  from
    user_objects
  where
    object_type in (
      'TABLE', 'VIEW', 'MATERIALIZED VIEW', 'PACKAGE', 
      'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SYNONYM'
    )
)
loop
begin if cur_rec.object_type = 'TABLE' then 
  execute immediate 
    'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '
" CASCADE CONSTRAINTS';

else 
  execute immediate 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"';

end if;

exception when others then DBMS_OUTPUT.put_line (
  'FAILED: DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"'
);

end;
end loop;
end;
/