oracle 如何防止 dbms_output.put_line 修剪前导空格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2584492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent dbms_output.put_line from trimming leading whitespace?
提问by Jared
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?
我试图右对齐某些 PL/SQL 代码的输出,但 dbms_output.put_line 正在修剪字符串中的前导空格。我如何让它停止?或者有没有更好的方法来输出带有前导空格的字符串?
dbms_output.put_line(lpad('string', 30, ' '));
outputs:
输出:
string
instead of:
代替:
string
回答by Peter Lang
The problem is not with dbms_output
but with SQL*Plus.
问题不在于dbms_output
SQL*Plus ,而在于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):
从文档(PDF)的SET SERVEROUT WORD_WRAPPED
(这是标准):
SQL*Plus left justifies each line, skipping all leading whitespace.
SQL*Plus 左对齐每一行,跳过所有前导空格。
回答by Joe
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.
这样,前导空格将被保留,但行长将由输出中文本的实际长度决定。