Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent output of SPOOL from being wrapped

I'm trying to generate all DDLs for objects in a Database using the SPOOL command in SQLPLUS:

SET trimspool ON
SET wrap off
SET heading off
SET linesize 300
SET echo off
SET pages 999
SET long 90000
Col object_type format a10000
Col object_name format a10000
Col owner format a10000

spool export.out

SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner)
FROM all_OBJECTS 
WHERE OWNER = 'DMALM' 
and object_type not like '%PARTITION'
and object_type not like '%BODY'
and object_type not like '%LOB';

spool off
quit

But the output file I get is cut at col #80. How can I prevent the output file from being wrapped?

like image 575
Filippo Avatar asked Aug 05 '14 15:08

Filippo


People also ask

What does set Serveroutput on do?

To redirect messages in the DBMS_OUTPUT message buffer to standard output, specify SET SERVEROUTPUT ON. In this example, the PUT procedure adds partial lines to the DBMS_OUTPUT message buffer. When proc1 runs, because SET SERVEROUTPUT ON is specified, the text stored in the DBMS_OUTPUT message buffer is displayed.

What is set Pagesize in Oracle?

The PAGESIZE setting tells SQL*Plus the number of printed lines that will fit on one page of output.

What is set Termout off in Oracle?

SET TERMOUT OFF suppresses the display so that you can spool output from a script without seeing it on the screen. If both spooling to file and writing to terminal are not required, use SET TERMOUT OFF in SQL scripts to disable terminal output.

How do I remove a trailing space in spool in Oracle?

The Oracle documentation says this about removing trailing spaces with "set trimspool" or "set trimout" commands: SET TRIMOUT ON or SET TRIMSPOOL ON removes trailing blanks at the end of each displayed or spooled line. Setting these variables ON can reduce the amount of data written.


2 Answers

You need to also do:

SET longchunksize 90000

As the documentation says:

The default width of datatype columns is the width of the column in the database. The column width of a LONG, BLOB, BFILE, CLOB, NCLOB or XMLType defaults to the value of SET LONGCHUNKSIZE or SET LONG, whichever is the smaller.

You're setting LONG already, but LONGCHUNKSIZE is still at its default value of 80, so you need to increase that to match. You can see all your current settings with show all.

This preserves the line breaks and indentation applied by default.

like image 139
Alex Poole Avatar answered Sep 18 '22 21:09

Alex Poole


How about using word_wrapped?

SET trimspool ON
SET heading off
SET linesize 300
SET echo off
SET pages 999
SET long 90000
set termout off
column txt format a121 word_wrapped
Col object_type format a10000
Col object_name format a10000
Col owner format a10000
spool export.out

SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner)txt
FROM all_OBJECTS 
WHERE OWNER = 'DMALM' 
and object_type not like '%PARTITION'
and object_type not like '%BODY'
and object_type not like '%LOB';

spool off
quit
like image 25
Fabio Carello Avatar answered Sep 20 '22 21:09

Fabio Carello