Use Oracle SQL statements to convert between systems

Source: Internet
Author: User

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

 
 
  1. select sum(data1)  
  2. from (select substr('1101', rownum, 1) * power(2, length('1101') - rownum) data1  
  3. from dual  
  4. connect by rownum <= length('1101')) 

Octal to decimal

 
 
  1. select sum(data1)  
  2. from (select substr('1101', rownum, 1) *  
  3. power(8, length('1101') - rownum) data1  
  4. from dual  
  5. connect by rownum <= length('1101')) 

Hexadecimal conversion to decimal

 
 
  1. select sum(data1)  
  2. from (select (CASE upper(substr('2D', rownum, 1))  
  3. WHEN 'A' THEN '10'  
  4. WHEN 'B' THEN '11'  
  5. WHEN 'C' THEN '12'  
  6. WHEN 'D' THEN '13'  
  7. WHEN 'E' THEN '14'  
  8. WHEN 'F' THEN '15'  
  9. ELSE substr('2D', rownum, 1)  
  10. END) * power(16, length('2D') - rownum) data1  
  11. from dual  
  12. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.