Oracle digital operations. numeric functions. MoD (), trunc (), round (), ceil (), Floor usage

Source: Internet
Author: User
Tags square root truncated

1, take the whole function (ceil up, floor down rounding)

The first way:

Select   $ /  -  from dual  -- rounding trunc (1.9) = 1

The second way

Select ceil (66.6) N1,floor (66.6 from dual;

2, exponentiation (Power) and square root (sqrt)

Select Power (3,2) N1,sqrt(9 from dual;

3, redundancy

Select MoD (9,5 from dual;

4, returns a fixed number of decimal digits (round: Rounding, Trunc: direct truncation)

Select round (66.667,2) N1,trunc (66.667,2 from

5, the sign of the return value (positive return is 1, negative number is-1)

Select  Sign (-+),sign (293 from dual;

1.round function (rounded)

Description: Returns a numeric value that is the result parameter of the rounding operation by the specified number of decimal places: Number: The value to be processed decimal_places: rounding, fractional numbers (preset 0)
Select round(123.456,0) fromdual; return 123Select round(123.456,1) fromDual Returns 123.5Select round(-123.456,2) fromDual Return-123.46

2.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 number n, and floor (N) takes the largest integer less than or equal to the value n
SelectCeil (1.5) A fromdual; Returns 2SelectCeil (-1.5) A fromDual Return-1Select  Floor(1.5) A fromdual; Returns 1Select  Floor(-1.5) A fromDual Return-2

1) trunc function handles numbers

TRUNC (Number[,decimals])

Where: number to be intercepted the value decimals indicates that the digits after the decimal point must be preserved. Optional, ignore it to truncate all the decimal parts.    Trunc is to deal with the number of display digits, if the decimals is negative, to deal with the integer part, the processing is 0,-1 you are zero, 2 to 10 bits, if the integer part length is exceeded, the entire number 0; 2) 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:
Trunc (Sysdate,'yyyy')--returns the first day of the year.Trunc (Sysdate,'mm')--returns the first day of the month.Trunc (Sysdate,'D')--returns the first day of the current week.Selecttrunc (Sysdate,'YYYY') fromDual;selecttrunc (Sysdate,'MM') fromDual;selecttrunc (Sysdate,'D') fromDual

Oracle digital operations. numeric functions. MoD (), trunc (), round (), ceil (), Floor usage

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.