Oracle batch export Stored Procedure

Source: Internet
Author: User

Oracle batch export Stored Procedure Method 1: PL/SQL tool export Method 2: SQL code SET echo off; SET heading off; SET feedback off; spool C: \ Documents and Settings \ Administrator \ Desktop \ proc. SQL; -- 1. If the sys user is used, use the SQL code select text from dba_source where owner = 'lingfeng' and type = 'Procedure '; -- 2. General users (users who want to export their stored procedures): SQL code select text from user_source; spool off; Method 3: (write your own Stored Procedure for export) 1. create DIRECTORYSql Code create or replace directory PROCE_DIR as 'C:/Documents and Settings/Administrator/desktop '. If an error is reported during creation, Log On as A system user, grant permissions to the current user -- grant statement SQL code grant create any directory to bijian; -- revoke statement SQL code revoke create any directory from bijian; after creation, you can use the following statement to check whether the SQL code is successfully created: select * from dba_directories; 2. create or replace procedure loadProce (owner varchar2) is type partition is table of user_source.text % type index by BINARY_INTEGER; user_source_table partition; file_handle partition; stor_text VARCHAR2 (4000 ); SQL _stat varchar2 (1000); SQL _stat2 varchar2 (1000); SQL _stat varchar2 (1000); nCount NUMBER; I NUMBER; begin SQL _stat: = 'select distinct (name) from all_source where owner = ''' | upper (owner) | '''; execute immediate SQL _stat bulk collect into user_source_table; file_handle: = utl_file.fopen ('proce _ dir ', 'test. SQL ', 'w'); for j in 1 .. user_source_table.count loop I: = 1; SQL _stat2: = 'select MAX (LINE) FROM ALL_SOURCE WHERE OWNER = ''' | upper (owner) | ''' and name = ''' | user_source_table (j) | '''; -- dbms_output.put_line (SQL _stat2); execute immediate SQL _stat2 into nCount; WHILE I <= nCount LOOP SQL _stat: = 'select TEXT FROM ALL_SOURCE WHERE OWNER = ''' | upper (owner) | ''' and name = ''' | user_source_table (j) | ''' and line = '| I; -- dbms_output.put_line (SQL _stat3 ); execute immediate SQL _stat3 into stor_text; I: = I + 1; utl_file.put (file_handle, stor_text); END LOOP; end loop; utl_file.fclose (file_handle); commit; end loadProce; 3. call to save the type body, PROCEDURE, TYPE, FUNCTION, TRIGGER, package body, and PACKAGE to test on the desktop. SQL code begin loadproce ('bijian '); end;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.