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;