Search code examples
oracle-databasedatabase-administration

Export specific oracle packages (specification and body) from sql prompt


We have to change existing packages but before we make any change we need to take backup of already (existing) packages in log/sql/text file. I would like to take backup of only those packages which we are going to change during release. We don't have SQL developer or any UI tool. We can run from SQL prompt.

Assume there are 3 packages owned by user 'usr33' package names usr33_pkg135 usr33_pkg234 usr33_pkg456

Is it possible? if yes, how?


Solution

  • One option is to use DBMS_METADATA package, such as

    select dbms_metadata.get_ddl('PACKAGE', 'USR33_PKG135', 'USR33') result
    from dual;
    

    Another one is to select text from USER_SOURCE:

    select text from user_source where name = 'USR33_PKG135'
    order by type, line;