Oracle SQL statements implement digital rounding and rounding _oracle

Source: Internet
Author: User

Rounding (rounding down):

Copy Code code as follows:
Select Floor (5.534) from dual;
Select Trunc (5.534) from dual;

The above two usages can be rounded down to the number 5.534, and the result is 5.

If you want to take the whole up and get a result of 6, you should use the Ceil

Copy Code code as follows:
Select Ceil (5.534) from dual;

Rounded:

Copy Code code as follows:
SELECT round (5.534) from dual;
SELECT round (5.534,0) from dual;
SELECT round (5.534,1) from dual;
SELECT round (5.534,2) from dual;

The results were 6, 6, 5.5, 5.53, respectively.

Keep n Decimal (not rounded):

Copy Code code as follows:
Select Trunc (5.534,0) from dual;
Select Trunc (5.534,1) from dual;
Select Trunc (5.534,2) from dual;

The result is 5,5.5,5.53, where a 0-digit decimal is the equivalent of a direct rounding.

Number formatting:

Copy Code code as follows:
Select To_char (12345.123, ' 99999999.9999 ') from dual;

Result is 12345.123

Copy Code code as follows:
Select To_char (12345.123, ' 99999999.9900 ') from dual;

After the decimal, the third fourth is insufficient to fill 0, the result is 12345.1230

Copy Code code as follows:
Select To_char (0.123, ' 99999999.9900 ') from dual;
Select To_char (0.123, ' 99999990.9900 ') from dual;

The results were. 123, 0.123

The above is the cloud Habitat Community Small series for everyone to organize the Oracle in the number of commonly used operations, the need for small partners can refer to.

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.