Export packages with "dbms_metadata.get_ddl"

0

I am exporting packages using dbms_metadata.get_ddl . For example:

select dbms_metadata.get_ddl('PACKAGE_BODY','NOMBRE_PAQ','SCHEMA_NA‌​ME') from dual;

But when generating the spool with the package code, a blank line is generated before CREATE OR REPLACE... .

How can I delete the blank line in the extraction?

I tried setting:

DBMS_METADATA.set_transform_param (DBMS_METADATA.session_transform, 'PRETTY', true)

... but it does not work.

    
asked by Sandra 28.11.2016 в 16:15
source

1 answer

0

Indeed, it's annoying, but dbms_metadata.get_ddl always returns a result that begins with the character for a new line (ascii 10).

If you want to remove it, you can use SUBSTR to to return everything except the first character:

select substr(dbms_metadata.get_ddl('PACKAGE_BODY','NOMBRE_PAQ','SCHEMA_NA‌​ME'), 2)
  from dual;

Or you can try TRIM :

select trim(leading chr(10) from dbms_metadata.get_ddl('PACKAGE_BODY','NOMBRE_PAQ','SCHEMA_NA‌​ME'))
  from dual;

Maybe using the conditional%% is better, in case there is some circumstance where the result will not start with a new line.

Demo .

    
answered by 29.11.2016 в 17:02