oracle convert string to hex,converting char to hex

SQL> ed

Wrote file afiedt.buf

1 with x as (select 'Fred' as txt from dual)

2 --

3 ,t as (select txt, regexp_substr(dump(txt),'[0-9,]*$') as bytes from x)

4 ,s as (select txt, rownum rn, to_number(regexp_substr(bytes,'[^,]+',1,rownum)) as byte

5 from t

6 connect by rownum <= length(regexp_replace(bytes,'[^,]*'))+1

7 )

8 ,b as (select txt, rn, byte, to_char(byte, 'fm0x') as hx

9 ,bitand(byte,128)/128||

10 bitand(byte,64)/64||

11 bitand(byte,32)/32||

12 bitand(byte,16)/16||

13 bitand(byte,8)/8||

14 bitand(byte,4)/4||

15 bitand(byte,2)/2||

16 bitand(byte,1) as bin

17 from s)

18 --

19 select txt

20 ,ltrim(sys_connect_by_path(byte,','),',') as bytes

21 ,replace(sys_connect_by_path(bin,','),',') as bin

22 ,replace(sys_connect_by_path(hx,','),',') as hx

23 from b

24 where connect_by_isleaf = 1

25 connect by rn = prior rn + 1

26* start with rn = 1

SQL> /

TXT BYTES BIN HX

---- ------------------------------ ---------------------------------------- --------------------

Fred 70,114,101,100 01000110011100100110010101100100 46726564

SQL>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值