Oracle/PLSQL: RawToHex Function

In Oracle/PLSQL, the rawtohex function converts a raw value into a hexadecimal value. One of our viewers says that this function comes in handy to move a varchar value to a blob field.

Syntax

The syntax for the rawtohex function is:

rawtohex( raw )

raw is the raw value to convert to a hexademical value.

Note

This function works differently when used as a PLSQL built-in function as opposed to running it in SQL. As a PLSQL function, rawtohex may perform an implicit conversion before converting to a hexadecimal value. This may result in a different value being returned by this function between PLSQL and SQL.

For example, if you ran the following:

declare

a varchar2(8);

begin

   a := rawtohex('AB');

   dbms_output.put_line(a);

   select rawtohex('AB') into a from dual;

   dbms_output.put_line(a);

end;

The following would be output as the result:

AB

4142

The reason for the difference is that PLSQL is doing an implicit conversion of 'AB' into a RAW (treats 'AB' as a single byte equal to chr(171)). A rawtohex on that returns the string 'AB'.

Whereas, SQL is not doing that implicit conversion. 'AB' is 2 byte RAW already and a rawtohex of that retuns 4142.

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

For Example

rawtohex('AB')

would return '4142' if run as an SQL function and 'AB' if run as a PLSQL function

rawtohex('7E')

would return '3745' if run as an SQL function and '7E' as a PLSQL function

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值