[20230417]sqlplus warpped word_warp.txt

lfree發表於2023-04-17

[20230417]sqlplus warpped word_warp.txt

--//今天除錯sql指令碼時遇到的情況,設定word_warp 如果前面有空格輸出會丟失的情況.
--//WARPPED用於折行,WARPPED按指定長度折行,WORD_WARPPED值按照完整字串折行
--//但是可能遇到奇怪的問題前面的空格不顯示的問題.透過例子說明.

1.環境:
SCOTT@book> @ ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.測試:
SCOTT@book> select dname from dept where deptno = 10;
DNAME
--------------
ACCOUNTING

SCOTT@book> column dname format a6
SCOTT@book> select dname from dept where deptno = 10;
DNAME
------
ACCOUN
TING
--//預設wrapped.出現折行.

SCOTT@book> column dname format a6 word_wrap
SCOTT@book> select dname from dept where deptno = 10;
DNAME
------
ACCOUN
TING
--//這樣看不出來,單詞ACCOUNTING有點長!!寫成如下:

SCOTT@book> select 'hello how are you' dname from dept where deptno = 10;
DNAME
------
hello
how
are
you
--//基本按照詞分隔.

SCOTT@book> column dname format a6 wrapped
SCOTT@book> select 'hello how are you' dname from dept where deptno = 10;
DNAME
------
hello
how ar
e you
--//沒有按照詞分隔.

--//如果開始部分存在空格呢?
SCOTT@book> select lpad(' ',10,' ')||dname dname from dept where deptno = 10;
DNAME
------

    AC
COUNTI
NG


SCOTT@book> column dname format a6 word_wrapped
SCOTT@book> select lpad(' ',10,' ')||dname dname from dept where deptno = 10;
DNAME
------
ACCOUN
TING
--//輸出丟失前面的空格!!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2946381/,如需轉載,請註明出處,否則將追究法律責任。