Oracle queries do not display 0 before the decimal point

Source: Internet
Author: User

1. The origin of the problem
When the Oracle database field value is less than 1 decimals, processing with char type loses 0 of the preceding decimal point
For example, 0.35 becomes. 35
2. WORKAROUND: Format the digital display with the TO_CHAR function
Select To_char (0.338, ' fm9999999990.00 ') from dual;
Results: 0.34
The focus here is to see the fm9999999999.99, which means that the integer part is up to 10 bits, the fractional part is 2 bits, and the FM indicates that the space before the transpose string is removed, and there are spaces before the fm,0.34.

Use of 3.with
With TMP1 as (
SELECT 1 as A, 2 as B from DUAL
UNION
SELECT 1 as A, 3 as B from DUAL
UNION
SELECT 1 as A, 4 as B from DUAL
),
TMP2 as (
SELECT 1 as A, 2 as B from DUAL
UNION
SELECT 1 as A, 3 as B from DUAL
UNION
SELECT 2 as A, 4 as B from DUAL
)
SELECT tmp1.*,tmp2.*
From TMP1 JOIN TMP2
On TMP1. A = TMP2. A

The author "strives forward"

After testing, the suspect is the number to char, the 0 before the decimal point

[SQL]View Plaincopy
  1. sql> Select To_char (num,' 999999999.999999999 ') from ml_test;
  2. To_char (NUM, ' 999999999.9999999
  3. ------------------------------
  4. .421240000
  5. .421246543
  6. 65432.421243240
  7. 4.621240000
  8. sql> Select To_char (num) from ml_test;
  9. To_char (NUM)
  10. ----------------------------------------
  11. .42124
  12. .4212465434
  13. 65432.42124324
  14. 4.62124
  15. sql> Select To_char (0.99) from dual;
  16. To_char (0.99)
  17. -------------
  18. .99


--4. How to solve the solution as follows

(1)

[SQL]View Plaincopy
  1. sql> Select To_nmber (To_char (0.99)) from dual;
  2. To_number (To_char (0.99))
  3. ------------------------
  4. 0.99
  5. sql> Select To_char (num,' fm999999990.999999999 ') from ml_test;
  6. To_char (NUM, ' FM999999990.99999
  7. ------------------------------
  8. 0.42124
  9. 0.421246543
  10. 65432.42124324
  11. 4.62124

(2) Using the case or Decode function, take the first digit is ".", 0, OK.

[SQL]View Plaincopy
    1. sql> Select To_char (num,' 999999999.999999999 ') from ml_test;
    2. To_char (NUM, ' 999999999.9999999
    3. ------------------------------
    4. .421240000
    5. .421246543
    6. 65432.421243240
    7. 4.621240000
    8. sql> Select To_char (num) from ml_test;
    9. To_char (NUM)
    10. ----------------------------------------
    11. .42124
    12. .4212465434
    13. 65432.42124324
    14. 4.62124
    15. sql> Select To_char (0.99) from dual;
    16. To_char (0.99)
    17. -------------
    18. .99

Oracle queries do not display 0 before the decimal point

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.