开发者

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


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.


Might add that if you want to preserve the leading spaces but trim the trailing spaces use:

set trimspool on

This way the leading spaces will be preserved but the line length will be determined by the actual length of text in the output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜