Oracle中如何进行进制转换(2进制,10进制,16进制)
1.16进制转换为10进制
可以通过to_number函数实现
SQL> select to_number('19f','xxx') from dual; TO_NUMBER('19F','XXX') SQL> select to_number('f','xx') from dual; TO_NUMBER('F','XX') |
2.10进制转换为16进制
可以通过to_char函数转换
SQL> select to_char(123,'xxx') from dual; TO_C SQL> select to_char(4567,'xxxx') from dual; TO_CH |
3.2进制转换为10进制
从Oracle9i开始,提供函数bin_to_num进行2进制到10进制的转换
SQL> select bin_to_num(1,1,0,1) a,bin_to_num(1,0) b from dual;
A B
----- ----------
13 2
SQL> select bin_to_num(1,1,1,0,1) from dual;
BIN_TO_NUM(1,1,1,0,1)
---------------------
29