注:
對其它進制可以根據例子將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"))