Oracle导出存储过程对象

℡╲_俬逩灬. 提交于 2020-02-27 05:54:07

$ pwd
/home/oracle

导出存储过程

$ vi test.par
INCLUDE=PROCEDURE:"IN ('P_TEST_LAST_DDL')"
SCHEMAS=scott

  

$ sqlplus / as sysdba

SQL> create directory backup as '/home/oracle';

Directory created.

SQL> grant write,read on directory backup to scott;

Grant succeeded.

$ sqlplus scott/tiger
SQL> create or replace procedure P_TEST_LAST_DDL
2 as
3 begin
4 null;
5 end;
6 /

Procedure created.

SQL> select status from user_objects a where a.object_name = 'P_TEST_LAST_DDL';

STATUS
--------------
VALID

 

$ expdp scott/tiger directory=backup parfile=test.par file=proceduretest.dmp

  

Export: Release 11.2.0.4.0 - Production on Mon Jun 17 17:53:10 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Legacy Mode Active due to the following parameters:
Legacy Mode Parameter: "file=proceduretest.dmp" Location: Command Line, Replaced with: "dumpfile=proceduretest.dmp"
Legacy Mode has set reuse_dumpfiles=true parameter.
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** directory=backup parfile=test.par dumpfile=proceduretest.dmp reuse_dumpfiles=true
Estimate in progress using BLOCKS method...
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/proceduretest.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Jun 17 17:53:12 2019 elapsed 0 00:00:02

 

 

$ sqlplus scott/tiger

SQL> create or replace function f_get_date
2 return varchar2
3 as
4 v_sysdate varchar2(30);
5 begin
6 select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') into v_sysdate from dual;
7 return v_sysdate;
8 end;
9 /

Function created.

SQL> select f_get_date from dual;

F_GET_DATE
--------------------------------------------------------------------------------
2019-06-17 17:58:09

 

导出函数

$ vi test.par
INCLUDE=PROCEDURE:"IN ('P_TEST_LAST_DDL')"
INCLUDE=FUNCTION:"IN ('F_GET_DATE')"
SCHEMAS=scott

$ expdp scott/tiger directory=backup parfile=test.par file=proceduretest2.dmp

  

 

 

Export: Release 11.2.0.4.0 - Production on Mon Jun 17 18:00:31 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Legacy Mode Active due to the following parameters:
Legacy Mode Parameter: "file=proceduretest2.dmp" Location: Command Line, Replaced with: "dumpfile=proceduretest2.dmp"
Legacy Mode has set reuse_dumpfiles=true parameter.
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** directory=backup parfile=test.par dumpfile=proceduretest2.dmp reuse_dumpfiles=true
Estimate in progress using BLOCKS method...
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/proceduretest2.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Jun 17 18:00:33 2019 elapsed 0 00:00:02

$ sqlplus scott/tiger

Create Or Replace Package Pkg_TEST_Demo Is

Type Gemp_Rec Is Record(
r_Empno Scott.Emp.Empno%Type,
r_Sal Scott.Emp.Sal%Type);

Procedure Show_Emp_Info;

Function Get_Sal(Emp_Id Number) Return Number;

End Pkg_TEST_Demo;
/


Create Or Replace Package Body PKG_TEST_DEMO Is

Procedure Show_Emp_Info Is
Cursor c_Emp Is
Select * From Scott.Emp;
Begin
For Emp_i In c_Emp Loop
Dbms_Output.Put_Line('员工姓名:' || Emp_i.Ename || ' 部门:' ||
Emp_i.Deptno);
End Loop;
Exception
When No_Data_Found Then
Dbms_Output.Put_Line('没有员工信息');
When Others Then
Dbms_Output.Put_Line('发生异常');
End Show_Emp_Info;

Function Get_Sal(Emp_Id Number) Return Number Is
l_Sal Scott.Emp.Sal%Type;
Begin
Select Sal Into l_Sal From Scott.Emp Where Empno = Emp_Id;
Dbms_Output.Put_Line(Emp_Id || '的工资是:' || l_Sal);
Return l_Sal;
Exception
When No_Data_Found Then
Dbms_Output.Put_Line('查无此人');
When Others Then
Dbms_Output.Put_Line('发生异常');
End Get_Sal;

End Pkg_TEST_Demo;
/

 

导出包(包头包体)

$ vi test.par
INCLUDE=PROCEDURE:"IN ('P_TEST_LAST_DDL')"
INCLUDE=FUNCTION:"IN ('F_GET_DATE')"
INCLUDE=PACKAGE:"IN ('PKG_TEST_DEMO')"
SCHEMAS=scott

$ expdp scott/tiger directory=backup parfile=test.par file=proceduretest3.dmp

  

 

 

Export: Release 11.2.0.4.0 - Production on Mon Jun 17 18:04:52 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Legacy Mode Active due to the following parameters:
Legacy Mode Parameter: "file=proceduretest3.dmp" Location: Command Line, Replaced with: "dumpfile=proceduretest3.dmp"
Legacy Mode has set reuse_dumpfiles=true parameter.
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** directory=backup parfile=test.par dumpfile=proceduretest3.dmp reuse_dumpfiles=true
Estimate in progress using BLOCKS method...
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_BODY
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/proceduretest3.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Jun 17 18:04:54 2019 elapsed 0 00:00:02

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!