实用的备份PL/SQL程序工具
发表于:2007-07-02来源:作者:点击数:
标签:
/*ligang1000@hotmail.com*/ 功能: 用于备份当前用户所拥有的所有PL/SQL objects (包括 TYPE,TYPE BODY, PROCEDURE , FUNCTION, PACKAGE, PACKAGE BODY or JAVA SOURCE ) 原理: 对USER_SOURCE数据字典的调用,得到所有的 PL/SQL 代码. 使用方法举例: 1. 在C盘
/*ligang1000@hotmail.com*/
功能: 用于备份当前用户所拥有的所有PL/SQL objects (包括
TYPE,TYPE BODY, PROCEDURE , FUNCTION, PACKAGE, PACKAGE BODY or JAVA SOURCE )
原理: 对USER_SOURCE数据字典的调用,得到所有的
PL/SQL 代码.
使用方法举例:
1. 在C盘建立目录C:\E
XPORT
2. 将EXPORT_SOURCE.SQL和EXTRACT_SOURCE.SQL拷贝到C盘根目录.
3. 登陆SQLPLUS , CONNECT SCOTT/TIGER
4. 运行@C:\EXPORT_SOURCE.SQL
5. 执行结束,所有的SCOTT拥有的PL/SQL object的代码文件建立在C:\EXPORT目录里.
后缀名.PKS 表示PACKAGE
后缀名.PKB 表示PACKAGE BODY
后缀名.SQL 表示其他OBJECTS
备注:
如果想得到
数据库中各个SCHEMA的PL/SQL objects ,只需把工具代码中的USER_SOURCE改成DBA_SOURCE,由SYSTEM
运行即可.
工具代码:
export_source.
sql SET SERVEROUTPUT ON SIZE 1000000
SET ECHO OFF VERIFY OFF FEEDBACK OFF TRIMSPOOL ON PAGES 0 LINES 512
SET TERMOUT OFF
SET TERMOUT ON
PROMPT
PROMPT PL/SQL export utility
PROMPT
PROMPT This utilty exports all of the current schema@#s PL/SQL source code into
PROMPT a subdirectory called export.
PROMPT
PROMPT Exporting current user@#s source to folder ./export
SET TERMOUT OFF
SPOOL temp_source_extract.sql
PROMPT SET ECHO OFF VERIFY OFF FEEDBACK OFF TRIMSPOOL ON TERMOUT OFF PAGES 0 LINES 512
DECLARE
/*
|| This cursor extracts each PL/SQL stored procedure@#s name and procedure type
*/
CURSOR cur_source_programs
IS
SELECT distinct us.name, us.type,
us.name || decode(us.type, @#PACKAGE@#, @#.PKS@#,
@#PACKAGE BODY@#, @#.PKB@#,
@#.SQL@#) spool_file
FROM user_source us
ORDER BY us.name, us.type;
BEGIN
FOR cur_source_programs_row IN cur_source_programs
LOOP
dbms_output.put_line(@#spool export\@# || user || @#_@# || cur_source_programs_row.spool_file);
dbms_output.put_line(@#@extract_source @# || cur_source_programs_row.name || @# "@# || cur_source_programs_row.type || @#"@#);
dbms_output.put_line(@#spool off@#);
END LOOP;
END;
/
SPOOL OFF
@temp_source_extract
SET FEEDBACK ON VERIFY ON TERMOUT ON
PROMPT Export complete!
PROMPT
Extract_source.sql:
SET HEAD OFF VERIFY OFF
prompt --************************************************************************************--;
prompt --*;
prompt --* SCRIPT: &2 &1;
prompt --*;
prompt --* AUTHOR:;
prompt --*;
prompt --*;
prompt --* PURPOSE:;
prompt --*;
prompt --*;
prompt --*;
prompt --*;
prompt --*;
prompt --* PARAMETERS:;
prompt --*;
prompt --*;
prompt --* DEPENDENCIES: none;
prompt --*;
prompt --* REVISIONS:;
prompt --* Ver Date Author Description;
prompt --* --------- ---------- ------------------ ------------------------------------;
prompt --* ;
prompt --*;
prompt --*************************************************************************************--;
SELECT DECODE(ROWNUM, 1, @#CREATE OR REPLACE @#|| RTRIM(RTRIM(us.text, CHR(10) )),
RTRIM(RTRIM(us.text, CHR(10) ))) text
FROM user_source us
WHERE us.name = @#&1@#
AND us.type = @#&2@#
ORDER BY us.line;
PROMPT /
PROMPT
原文转自:http://www.ltesting.net