HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

How in Oracle can I export package that will have package and body?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canpackagewillthatexporthowandbodyoraclehave

Problem

I'm using putty. How in Oracle can I export package and its body to a file in present directory using spool?

Thanks

Solution

There are two ways to achieve this

Way 1 :

SET HEAD OFF
SET ECHO OFF
SET FEED OFF
SET TERM OFF
SET LINE 1500
SET NEWPAGE NONE
set pagesize 0
SPOOL C:\temp\FILE_NAME.SQL
PROMPT CREATE OR REPLACE
select trim(text) from user_source
where name='PACKAGE_NAME' AND type='PACKAGE';
SPOOL OFF


Way 2:

select dbms_metadata.get_ddl('PACKAGE','PACKAGE_NAME',USER) from dual;


Another way suggested by @vercelli that is exporting the package and it's body using Oracle expdp utility. A wonderfull method :)

expdp scott/tiger@db10g schemas=SCOTT INCLUDE=PACKAGE LIKE 'PACKAGE_NAME' SQLFILE=scott.sql directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log


Hope this helps !!

Regards.

Code Snippets

SET HEAD OFF
SET ECHO OFF
SET FEED OFF
SET TERM OFF
SET LINE 1500
SET NEWPAGE NONE
set pagesize 0
SPOOL C:\temp\FILE_NAME.SQL
PROMPT CREATE OR REPLACE
select trim(text) from user_source
where name='PACKAGE_NAME' AND type='PACKAGE';
SPOOL OFF
select dbms_metadata.get_ddl('PACKAGE','PACKAGE_NAME',USER) from dual;
expdp scott/tiger@db10g schemas=SCOTT INCLUDE=PACKAGE LIKE 'PACKAGE_NAME' SQLFILE=scott.sql directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log

Context

StackExchange Database Administrators Q#147831, answer score: 4

Revisions (0)

No revisions yet.