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
- sql> Select To_char (num,' 999999999.999999999 ') from ml_test;
- To_char (NUM, ' 999999999.9999999
- ------------------------------
- .421240000
- .421246543
- 65432.421243240
- 4.621240000
- sql> Select To_char (num) from ml_test;
- To_char (NUM)
- ----------------------------------------
- .42124
- .4212465434
- 65432.42124324
- 4.62124
- sql> Select To_char (0.99) from dual;
- To_char (0.99)
- -------------
- .99
--4. How to solve the solution as follows
(1)
[SQL]View Plaincopy
- sql> Select To_nmber (To_char (0.99)) from dual;
- To_number (To_char (0.99))
- ------------------------
- 0.99
- sql> Select To_char (num,' fm999999990.999999999 ') from ml_test;
- To_char (NUM, ' FM999999990.99999
- ------------------------------
- 0.42124
- 0.421246543
- 65432.42124324
- 4.62124
(2) Using the case or Decode function, take the first digit is ".", 0, OK.
[SQL]View Plaincopy
- sql> Select To_char (num,' 999999999.999999999 ') from ml_test;
- To_char (NUM, ' 999999999.9999999
- ------------------------------
- .421240000
- .421246543
- 65432.421243240
- 4.621240000
- sql> Select To_char (num) from ml_test;
- To_char (NUM)
- ----------------------------------------
- .42124
- .4212465434
- 65432.42124324
- 4.62124
- sql> Select To_char (0.99) from dual;
- To_char (0.99)
- -------------
- .99
Oracle queries do not display 0 before the decimal point