Zero loss before decimal point in oracle

Source: Internet
Author: User

1. Origin
When the oracle database field value is less than 1 decimal point, the char type is used for processing, and the 0 before the decimal point is lost.
For example, 0.35 is changed to. 35.
2. Solution: Use the to_char function to format the number display.
Select to_char (0.338, 'fm9999999990. 00') from dual;
Result: 0.34
Here we will focus on fm9999999999.99, which indicates that the integer part can be up to 10 digits, and the fractional part can be 2 digits. fm indicates that the leading space after the index string is removed, without fm, and there will be spaces before 0.34.

3. Use of
WITH TMP1 (
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 (
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

Author "striving forward"
 

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.