12
返回列表 发新帖
楼主: jlandzpa

关于rawtohex的一个奇怪问题,哪位解释一下

[复制链接]
论坛徽章:
60
2007年度最佳版主
日期:2008-04-03 16:46:15现任管理团队成员
日期:2011-05-07 01:45:08双黄蛋
日期:2011-06-15 17:03:34ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
11#
发表于 2002-9-10 16:23 | 只看该作者
Oracle 8.1.7

SQL> ed
......

1 declare
2 a varchar2(100);
3 begin
4 select rawtohex('aaaa') into a from dual;
5 dbms_output.put_line(a);
6* end;
SQL> /
61616161

--it's right



SQL> ed
.............

1 declare
2 a varchar2(100);
3 begin
4 a:=rawtohex('aaaa');
5 dbms_output.put_line(a);
6* end;
SQL> /
AAAA

--but it's wrong result

why?thank you!!




--------------------------------------------------------------------------------
and we said...

Actually, AAAA is the "right" result if you ask me.


rawtohex -- function that expects RAW, returns HEX output.

'aaaa' is a character string, hence there should be an implicit hextoraw wrapped
around it.

'aaaa' is a 2 byte raw, the output of rawtohex( <2 byte raw> ) would be 4
characters long (2 byte raw = 4 byte string)


This is just yet another reason to ALWAYS avoid implicit conversions!!!!  Always
-- to me, rawtohex( <string> ) should be the same as rawtohex( hextoraw(
<string> ) ) since rawtohex expects a raw, not a string.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表