注:
对其它进制可以根据例子将power的底数改成相应的进制就可以了。
本文只是一个例子,大家可以把它封装成一个通用函数进行实用。
大家在试的时候将里面相应的其它进制的数值换成自己的数据就可以了(有多处)。
-----二进制转换十进制-----------------
select sum(data1)
from (select substr("1101", rownum, 1) * power(2, length("1101") - rownum) data1
from dual
connect by rownum <= length("1101"))
-----八进制转换十进制-----------------
select sum(data1)
from (select substr("1101", rownum, 1) * power(8, length("1101") - rownum) data1
from dual
connect by rownum <= length("1101"))
-----十六进制转换十进制-----------------
select sum(data1)
from (select (CASE upper(substr("2D", rownum, 1))
WHEN "A" THEN "10"
WHEN "B" THEN "11"
WHEN "C" THEN "12"
WHEN "D" THEN "13"
WHEN "E" THEN "14"
WHEN "F" THEN "15"
ELSE substr("2D", rownum, 1)
END) * power(16, length("2D") - rownum) data1
from dual
connect by rownum <= length("2D"))
本文作者:未知