How to prevent dbms_output.put_line from trimming leading spaces?

I am trying to correctly align the output of some PL / SQL code, but dbms_output.put_line trims leading spaces from my lines. How to make him stop? Or is there a better way to output strings with leading spaces?

dbms_output.put_line(lpad('string', 30, ' ')); 

outputs:

 string 

instead:

  string 
+6
sql oracle plsql sqlplus
source share
2 answers

The problem is not dbms_output , but SQL * Plus.

Using

 SET SERVEROUTPUT ON FORMAT WRAPPED 

or

 SET SERVEROUTPUT ON FORMAT TRUNCATED 

to save spaces.


From the documentation (PDF) of SET SERVEROUT WORD_WRAPPED (which is the standard):

SQL * Plus leaves the alignment of each line, skipping all leading spaces.

+15
source share

You can add that if you want to keep leading spaces, but trim trailing spaces: set trimspool on in your sql. This way, leading spaces will be retained, but the length of the line will be determined by the actual length of the text in the output.

+3
source share

All Articles