The following article mainly introduces how to use Oracle SQL statements to convert between systems. This article uses the actual code to implement conversions between systems. Based on the actual example, you can change the base number of power to the corresponding base number.
The following describes Oracle SQL statements:
This article is just an example. You can encapsulate it into a common function for practical use. During the test, you can replace the corresponding other hexadecimal values with your own data.
Binary Conversion to decimal
- select sum(data1)
- from (select substr('1101', rownum, 1) * power(2, length('1101') - rownum) data1
- from dual
- connect by rownum <= length('1101'))
Octal to decimal
- select sum(data1)
- from (select substr('1101', rownum, 1) *
- power(8, length('1101') - rownum) data1
- from dual
- connect by rownum <= length('1101'))
Hexadecimal conversion to decimal
- 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'))
The above content is an introduction to Oracle SQL statements to implement inter-System Conversion. I hope you will gain some benefits.