Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent dbms_output.put_line from trimming leading whitespace?

I am trying to right-align the output of some PL/SQL code, but dbms_output.put_line is trimming the leading whitespace from my strings. How do I make it stop? Or is there a better way to output strings with leading whitespace?

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

outputs:

string

instead of:

                        string
like image 587
Jared Avatar asked Apr 06 '10 11:04

Jared


People also ask

What is the maximum line size that DBMS_OUTPUT can handle?

Rules and Limits The maximum line size is 32767 bytes. The default buffer size is 20000 bytes. The minimum size is 2000 bytes and the maximum is unlimited.

Does DBMS_OUTPUT Put_line affect performance?

Every extra line of code decreases the performance of code. After all, it is an extra instruction to be executed, which at least consumes some CPU. So yes, dbms_output. put_line decreases the performance.

What command should you try if DBMS_OUTPUT Put_line?

When using the dbms output. put line command, either the server output is not enabled or there is a bug in the code. Until executing the PL/SQL command, make sure that the server output is turned on. If there is a code error, it should be fixed.


1 Answers

The problem is not with dbms_output but with SQL*Plus.

Use

SET SERVEROUTPUT ON FORMAT WRAPPED

or

SET SERVEROUTPUT ON FORMAT TRUNCATED

to preserve the spaces.


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

SQL*Plus left justifies each line, skipping all leading whitespace.

like image 123
Peter Lang Avatar answered Sep 23 '22 02:09

Peter Lang