Oracle数据库批量删除表、视图、序列、存储过程、函数脚本

批量删除表、视图、序列、存储过程、函数前,生成对应的SQL执行脚本,然后执行生成对应的脚本即可:
一、删除数据库表
    -- 生成删除oracle数据库表的脚本语句
    select 'drop table ' || table_name || ';' as sqlscript from user_tables; --delete tables
    
    -- 带过滤条件删除oracle数据库表的脚本语句
    select 'drop table ' || a.table_name || ';    --' || a.comments
    from user_tab_comments a
    where a.table_type in ('TABLE') and table_name like 'test_%';

二、删除数据库表序列
    --删除序列
    select 'drop sequence ' || sequence_name || ';' as sqlscript from user_sequences; --delete seqs
    
    --过滤条件删除序列
    select 'drop sequence ' || sequence_name || ';' as sqlscript from user_sequences where sequence_name like 'SEQ_TEST_LOG_%';

三、删除存储过程
select 'drop procedure ' || object_name || ';' as sqlscript from user_objects  where object_type = 'PROCEDURE';  --DELETE PROCEDURE

四、删除抽象数据类型
select 'drop type ' || type_name || ';' as sqlscript from user_types; --delete types

五、删除视图
select 'drop view ' || view_name || ';' as sqlscript from user_views;  --delete views

六、删除函数
select 'drop function ' || object_name || ';' as sqlscript from user_objects  where object_type = 'FUNCTION';--delete functions

七、删除包
select 'drop package ' || object_name|| ';' as sqlscript from user_objects  where object_type = 'PACKAGE';--delete pags

八、Oracle生成批量清空表数据脚本
select 'DELETE FROM ' || a.table_name || ';      --' || a.comments
from user_tab_comments a
where a.table_type in('TABLE') and table_name not like 'SYS_%'
posted @ 2022-11-25 11:48  深海蓝精灵  阅读(1298)  评论(0编辑  收藏  举报