Analysis of zero loss before decimal point based on oracle

  • 2021-07-09 09:28:20
  • OfStack

1. Origin of the problem
When the oracle database field value is a decimal less than 1, the 0 before the decimal point is lost when processed with the char type
For example, 0.35 becomes. 35

2. Solution: Formatting the numeric display with the to_char function
select to_char(0.338,'fm9999999990.00') from dual;
Result: 0.34
Here, we should focus on fm99999999999.99, which means that the integer part has a maximum of 10 digits and the decimal part has 2 digits. fm means that the space before the indexed string is removed, and there will be a space before 0.34 without fm.


Related articles: