Use of trunc functions, round functions, ceil functions, and floor functions in Oracle

Source: Internet
Author: User
Tags truncated

1.1trunc function handles numbers

The TRUNC function returns the processed value, and its working mechanism is very similar to the round function, except that the function does not make the corresponding rounding selection processing of the specified fractional number before or after it, and it is truncated altogether. Its specific syntax format is as follows Trunc (Number[,decimals]) Where: number to intercept the value of the interception process decimals indicate that you need to retain the digits after the decimal point. Optional, ignore it to truncate all the decimal parts.
1 Select trunc (123.98) from dual; 2 Select trunc (123.123,2) from dual; 3 Select trunc (123.123,-1) from dual;

Note: The second parameter can be a negative number, which means that the portion of the digits to the left of the decimal point is truncated to 0. Similar to rounding, such as a parameter of 1 is rounded to a very bit, if 1, is rounded to 10 bits, and so on; If the parameter set is negative, and the number of negative digits is greater than or equal to the number of bytes of the integer, then the return is 0. such as: TRUNC (89.985,-3) = 0.

1.2trunc function Processing Date the TRUNC function returns a date value that is partially truncated in the specified element format. Its specific syntax format is as follows: TRUNC (Date,[fmt]) Where: date is the necessary parameter, is the input of a date value the FMT parameter can be ignored, is the date format, used to specify the element format to intercept the input date value. Ignoring it is truncated by the nearest date. The following is the usage of the function:
1Trunc (Sysdate,'yyyy')--returns the first day of the year.2Trunc (Sysdate,'mm')--returns the first day of the month.3Trunc (Sysdate,'D')--returns the first day of the current week.4 SelectTrunc (Sysdate,'YYYY') fromdual;5 SelectTrunc (Sysdate,'MM') fromdual;6 SelectTrunc (Sysdate,'D') fromDual

2.round function (rounded)

Description: Returns a numeric value that is the result of rounding operations by the specified number of decimal digits.

1 SELECT ROUND  Number [] from DUAL

Parameters:

Number: The value to be processed decimal_places: rounding, Decimals (preset to 0)
1 Sample:2 Select round(123.456,0) fromDual Return1233 Select round(123.456,1) fromDual Return123.54 Select round(-123.456,2) fromDual Return-123.46

3.ceil and Floor functions

The ceil and floor functions are sometimes useful when it comes to business data. Ceil (n) takes the smallest integer greater than or equal to the value N, and Floor (N) takes the largest integer less than or equal to the value N; turn from: http://www.2cto.com/database/201310/248336.html

Use of trunc functions, round functions, ceil functions, and floor functions in Oracle

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.