Oracle's functions for processing decimal places

Source: Internet
Author: User

Oracle functions for processing decimal digits ()
1. Take the rounded decimal places
Select round (1.2345, 3) from dual;
Result: 1.235
2. retain the two decimal places.
Select trunc (1.2345, 2) from dual;
Result: 1.23

Select trunc (1.2399, 2) from dual;
Result: 1.23
3. Take an integer
Returns the largest integer greater than or equal to x:
SQL> select ceil (23.33) from dual;
Result: 24

Returns the largest integer equal to or less than x:
SQL> select floor (23.33) from dual;
Result: 23

Returns the value of x rounded to the right of the decimal point, which is rcund (x, [y]).
SQL> select role (23.33) from dual;
Result: 23

Returns x rounded to y decimal places: trunc (x, [y]).
SQL> select trunc (23.33) from dual;
Result: 23


Format a number

The following are number examples for the to_char function.


To_char (1210.73, '192. 9') wocould return '192. 7'
To_char (1210.73, '20140901') wocould return '20160301'
To_char (1210.73, '$9,999.00') wocould return '$1,210.73'
To_char (21, '20140901') wocould return '20160901'


Special usage of to_char Function
To_char (sysdate, 'D') day of each week
To_char (sysdate, 'dd') day of each month
To_char (sysdate, 'ddd ') day of each year
To_char (sysdate, 'ww ') week of each year
To_char (sysdate, 'mm') month of each year
To_char (sysdate, 'q') quarter of each year
To_char (sysdate, 'yyyy') year
For example, if you want to find the day of the week
SQL> select to_char (to_date ('201312', 'yyyymmdd'), 'D') from dual;

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.