ITPub博客

首页 > 数据库 > Oracle > [20230807]为什么不对齐.txt

[20230807]为什么不对齐.txt

原创 Oracle 作者:lfree 时间:2023-08-11 21:15:37 0 删除 编辑

[20230807]为什么不对齐.txt

SCOTT@test01p> select * from v$version;
BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production              0
PL/SQL Release 12.2.0.1.0 - Production                                                    0
CORE    12.2.0.1.0      Production                                                                0
TNS for 64-bit Windows: Version 12.2.0.1.0 - Production                                   0
NLSRTL Version 12.2.0.1.0 - Production                                                    0

--//看到这个输出,一直不明白为什么其中1行不对齐的情况,探究看看。
SCOTT@test01p> column c90 format a90
SCOTT@test01p> select dump(banner,16) c90,banner from v$version where banner like 'CORE%';
C90                                                                                        BANNER
------------------------------------------------------------------------------------------ --------------------------------
Typ=1 Len=26: 43,4f,52,45,9,31,32,2e,32,2e,30,2e,31,2e,30,9,50,72,6f,64,75,63,74,69,6f,6e  CORE 12.2.0.1.0      Production

--//可以看出CORE,12.2.0.1.0,Production之间的字符ascii码是0x9.相当于<tab>字符,也就是字符之间使用<tab>连接。
--//不知道为什么会影响到第2个字段的输出位置。

SCOTT@test01p> set COLSEP |
SCOTT@test01p> select * from v$version ;
BANNER                                                                          |    CON_ID
--------------------------------------------------------------------------------|----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production    |         0
PL/SQL Release 12.2.0.1.0 - Production                                          |         0
CORE    12.2.0.1.0      Production                                                      |         0
TNS for 64-bit Windows: Version 12.2.0.1.0 - Production                         |         0
NLSRTL Version 12.2.0.1.0 - Production                                          |         0

--//改写如下:

SCOTT@test01p> select replace(banner,chr(9),' '),con_id from v$version ;
REPLACE(BANNER,CHR(9),'')                                                            CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production              0
PL/SQL Release 12.2.0.1.0 - Production                                                    0
CORE 12.2.0.1.0 Production                                                                0
TNS for 64-bit Windows: Version 12.2.0.1.0 - Production                                   0
NLSRTL Version 12.2.0.1.0 - Production                                                    0

--//不知道sqlplus能够设置什么参数避免这样的情况出现!!那位知道.就在我无法分析时候我发现
select dump(banner,16) c90,banner from v$version where banner like 'CORE%';
--//输出CORE,12.2.0.1.0之间仅仅占用1个字符.而CORE 12.2.0.1.0之间的空格字符通过vim定位可以发现在列96.
--//一般缺省tabstop=8,出现字符的位置(8*N+1) 9,17,25.....
CORE    12.2.0.1.0    Production
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123456789012345678901234567890

--//也就是将这个输出一行当做1个字符串来处理,但是还是无法解析我看到的情况.
SYS@test> select '1     2       3' c80 , 0 con_id from dual ;
C80                                                                             |    CON_ID
--------------------------------------------------------------------------------|----------
1       2       3                                                                           |         0

SYS@test> select '1     23' c80 , 0 con_id from dual ;
C80                                                                             |    CON_ID
--------------------------------------------------------------------------------|----------
1       23                                                                            |         0

SYS@test> select '123   ' c80 , 0 con_id from dual ;
C80                                                                             |    CON_ID
--------------------------------------------------------------------------------|----------
123                                                                                 |         0

SYS@test> select '      123' c80 , 0 con_id from dual ;
C80                                                                             |    CON_ID
--------------------------------------------------------------------------------|----------
        123                                                                            |         0

--//没有任何规律可言!!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2969872/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969578