oracle 自动生存清库脚本

在项目上为了搭建测试库,常常会遇到要清除现在的库,很是折腾,闲暇之余,写了一个脚本留作备用。

脚本如下:

select '--清表' from dual union all select 'drop table ' ||a.TABLE_NAME ||''||';' from  user_tables a union  all select '--清序列' from dual --清序列 union all select 'drop sequence '|| a.sequence_name||''  ||';' from user_sequences  a --清存储过程 union all select '--清存储过程' from dual union all select  'drop procedure  '|| a.object_name||''  ||';'  from user_procedures  a where a.object_type='PROCEDURE' --清包 union all select '--清包' from dual union all select distinct  'drop PACKAGE  '|| a.object_name||''  ||';'  from user_procedures  a where a.object_type='PACKAGE' union all select '--清自定义函数' from dual union all select 'drop FUNCTION '|| a.object_name||''  ||';'   from user_procedures    a where a.object_type ='FUNCTION'

在pl/sql里面运行之后自动生存执行的命令复制之后,

新建一个 command window 窗口,把复制好的命令粘贴到窗口里面,直接运行就可以了。

最后执行下面的语句生成导库语句

--导入库

select 'imp 用户名/密码@数据库 file='||'dmp文件'||' full=y' from dual

打开cmd 窗口,标记一下上面复制的导库命令,修改一下,回车即可。

--导出库

select 'exp 用户名/密码@数据库 file='||'dmp文件'||' full=y' from dual

原文地址:https://www.cnblogs.com/cegh/p/4147951.html