--16进制转10进制,用to_number,里面的参数是16进制的数据,且参数用单引号括起
SQL> select to_number('ff','xx') from dual;
TO_NUMBER('FF','XX')
--------------------
255
--10进制转16进制,用to_char,里面的参数是10进制的数据,且参数不用单引号括起
SQL> select to_char(255,'xx') from dual;
TO_CHAR(255,'XX')
-----------------
ff
--如下报错因为要转换的16进制的数据宽度与格式串的xx宽度不一样
SQL> select to_number('10effff','xx') from dual;
select to_number('10effff','xx') from dual
ORA-01722: 无效数字
--续上,修正二者宽度一致,不再报错
SQL> select to_number('10effff','xxxxxxx') from dual;
TO_NUMBER('10EFFFF','XXXXXXX')
------------------------------
17760255
--格式串的宽度>=要转化的数据宽度也可以
SQL> select to_number('10effff','xxxxxxx') from dual;
TO_NUMBER('10EFFFF','XXXXXXX')
------------------------------
17760255
SQL> select to_number('e','xxxxxxx') from dual;
TO_NUMBER('E','XXXXXXX')
------------------------
14