--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
ide
--格式串的寬度>=要轉化的數據寬度也能夠
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')
------------------------
14it