The Oracle function to_char converts the number of digits to the decimal point.

Source: Internet
Author: User

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:

 
 
  1. 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:

 
 
  1. 'NLS_NUMERIC_CHARACTERS="dg" NLS_CURRENCY="tcxt" 
    NLS_ISO_CURRENCY=territory' 

D indicates the decimal point, and g indicates the group separator.

Example:

 
 
  1. 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.

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.