ITPub博客

首页 > 数据库 > Oracle > [20260825]sqlplus输入nul字符问题.txt

[20260825]sqlplus输入nul字符问题.txt

原创 Oracle 作者:lfree 时间:2026-08-27 21:12:24 0 删除 编辑

[20260825]sqlplus输入nul字符问题.txt

--//上午测试遇到的问题,单独拿出来做一个记录.

1.环境:
SYS@book> @ ver2
==============================
PORT_STRING                   : x86_64/Linux 2.4.xx
VERSION                       : 21.0.0.0.0
BANNER                        : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
BANNER_FULL                   : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
BANNER_LEGACY                 : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
CON_ID                        : 0
PL/SQL procedure successfully completed.

2.问题:
--//使用bpftrace内容如下:
krqhsh Begin
[15:57:23] kgghash #07 pid=3809 hash_text=4(\x01\x00 length=4 seed=0
[15:57:23] kgghash #07 pid=3809 return hash_value=00000000af89b23f 2945036863 000000000000323f 12863
[15:57:23] kgghash #08 pid=3809 hash_text=BOOK01P length=7 seed=af89b23f
[15:57:23] kgghash #08 pid=3809 return hash_value=00000000feac3df8 4272700920 0000000000003df8 15864
krqhsh End

--//hash_text=4(\x01\x00,开始想直接采用字符串输入计算。

$ cat ora_hash1.txt
select
 ora_hash('&&1',4294967295,&2) n20
,to_char(ora_hash('&1',4294967295,&2),'FM0xxxxxxxxxxxxxxx')  c20
from dual;

$ cat ora_hash2.txt
select
 ora_hash(UTL_RAW.cast_to_varchar2(hextoraw('&1')),4294967295,&2) n20
,to_char(ora_hash(UTL_RAW.cast_to_varchar2(hextoraw('&1')),4294967295,&2),'FM0xxxxxxxxxxxxxxx')  c20
from dual;

--//使用vi的二进制编辑模式:
$ xxd -c 32 a.txt
00000000: 4020 6f72 615f 6861 7368 312e 7478 7420 2234 2801 0022 2030 0a                   @ ora_hash1.txt "4(.." 0.

SYS@book> @ ora_hash2.txt 34280100 0

                  N20 C20
--------------------- --------------------
           2945036863 00000000af89b23f

SYS@book> @ a.txt

                  N20 C20
--------------------- --------------------
           3652849166 00000000d9ba0e0e
           
--//发现2者计算结果不同。

SYS@book> define 1
DEFINE 1               = "4(" (CHAR)

SYS@book> select length('&1') from dual ;
LENGTH('4(')
-------------
            3

--//可以发现\x00字符给丢弃了。仅仅3个字符进行参与计算.
SYS@book> @ ora_hash2.txt 342801 0
                  N20 C20
--------------------- --------------------
           3652849166 00000000d9ba0e0e

--//不过想到一个变通的方法输入如下,只要''匹配:
SYS@book> @ ora_hash1.txt "4('||chr(1)||chr(0)||'" 0
                  N20 C20
--------------------- --------------------
           2945036863 00000000af89b23f

3.补充:
--//顺便补充一些vim方法的一些操作知识,平时很少使用。
ga 可以看对应字符的8,10,16进制编码
g8 可以看对应字符的16进制编码

--//实际上可以输入\x01以及\x00字符,在插入状态下:
--//windows 下按ctrl+q ,ctrl+A 对应chr(1)
--//windows 下按ctrl+q ,ctrl+@ 对应chr(0)

--//linux下按ctrl+v 代替ctrl+q,  

--//在tmux的vim下使用,ctrl+a 已经被我定义tmux的前缀按键
unbind ^b
set -g prefix c-a

--//要按2次ctrl+a才生效.

--//修改a.txt如下,\x01\x00 变成 \x00\x01
$ xxd -c 32  a.txt
00000000: 4020 6f72 615f 6861 7368 312e 7478 7420 2234 2800 0122 2030 0a                   @ ora_hash1.txt "4(.." 0.

SYS@book> @ a.txt
                  N20 C20
--------------------- --------------------
           3652849166 00000000d9ba0e0e
--//与前面的计算一样。

SYS@book> define 1
DEFINE 1               = "4(" (CHAR)

SYS@book> select length('&1') from dual ;

LENGTH('4(')
-------------
            3

--//可以发现\x00字符给丢弃了,即使在字符串中间,仅仅3个字符进行参与计算.

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

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

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969087