oracle删除用户下所有的表

时间:2022-05-17 01:19:36
需要创建这些删除语句,通过oracle的数据字典找到该用户下的所有表、视图等对象,拼接成语句。如下
select 'drop table '||table_name|| ' cascade constraints;'from user_tables
select 'drop table ' || table_name ||';'||chr(13)||chr(10) from user_tables; --delete tables
select 'drop view ' || view_name||';'||chr(13)||chr(10) from user_views; --delete views
select 'drop sequence ' || sequence_name||';'||chr(13)||chr(10) from user_sequences;--delete seqs
select 'drop function ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='FUNCTION';--delete functions
select 'drop procedure ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='PROCEDURE';--DELETE PROCEDURE
select 'drop package ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='PACKAGE';--delete pags 执行完上述语句后,会生成对用的删除语句,复制到命令行执行即可。