|
|
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. |
|