In the Oracle function to_char to convert the number type to specify the number of digits of the corresponding decimal point, we need to use the relevant functions to convert the numeric or date type to the numeric type, the following is a detailed description of the article, and I hope you will get some benefits.
For example, the simplest application:
Select TO_CHAR (1.0123) FROM DUAL
Select TO_CHAR (123) FROM DUAL
Next let's take a look at the following:
SELEC TO_CHAR (0.123) FROM DUAL
The above result '. 100' is not what we want in most cases. What we want is '0. 100 '.
Let's take a look at the specific usage of the to_char function:
- TO_CHAR ( n [, fmt [, 'nlsparam']] )
This Oracle function converts n of the NUMBER type into a value of the VARCHAR2 type in the numerical format fmt. 'Nlsparams' specifies the characters returned by the element in numerical format, including:
. Decimal point character
. Group Separator
. Local coin symbol
. International coin symbol
The form of Yuan change is:
- 'NLS_NUMERIC_CHARACTERS="dg" NLS_CURRENCY="tcxt"
NLS_ISO_CURRENCY=territory'
D indicates the decimal point, and g indicates the group separator.
Example:
- TO_CHAR (17145,'L099G999','NLS_NUMERIC_CHARACTERS=".,"
NLS_CURRENCY="NUD"')=NUD017,145
Based on the above understanding, and then look at some fmt formats, we can use the following expression to get the value of '0. 123:
Select TO_CHAR (0.123, '0. 999 ') FROM DUAL
Select TO_CHAR (100.12, '0. 999 ') FROM DUAL
Select TO_CHAR (1.12, '0. 999 ') FROM DUAL
'123' is displayed, but there is a space in front.
The value of 100.12 is, and the value of '1. 12' is changed to '1. 12 '.
The above content is an introduction to the Oracle function to_char to convert the number type to the specified number of decimal places. I hope you will get something.