Oracle/PLSQL: Trunc Function (with dates):
http://www.techonthenet.com/oracle/functions/trunc_date.php
引用
In Oracle/PLSQL, the trunc function returns a date truncated to a specific unit of measure.
The syntax for the trunc function is:
trunc ( date, [ format ] )
date is the date to truncate.
format is the unit of measure to apply for truncating. If the format parameter is omitted, the trunc function will truncate the date to the day value, so that any hours, minutes, or seconds will be truncated off.
Below are the valid format parameters:
Applies To:
Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
For example:
trunc(to_date('22-AUG-03'), 'YEAR') would return '01-JAN-03'
trunc(to_date('22-AUG-03'), 'Q') would return '01-JUL-03'
trunc(to_date('22-AUG-03'), 'MONTH') would return '01-AUG-03'
trunc(to_date('22-AUG-03'), 'DDD') would return '22-AUG-03'
trunc(to_date('22-AUG-03'), 'DAY') would return '17-AUG-03'
Oracle/PLSQL: Trunc Function (with numbers):
http://www.techonthenet.com/oracle/functions/trunc_nbr.php
引用
In Oracle/PLSQL, the trunc function returns a number truncated to a certain number of decimal places.
The syntax for the trunc function is:
trunc( number, [ decimal_places ] )
number is the number to truncate.
decimal_places is the number of decimal places to truncate to. This value must be an integer. If this parameter is omitted, the trunc function will truncate the number to 0 decimal places.
Applies To:
Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
For example:
trunc(125.815) would return 125
trunc(125.815, 0) would return 125
trunc(125.815, 1) would return 125.8
trunc(125.815, 2) would return 125.81
trunc(125.815, 3) would return 125.815
trunc(-125.815, 2) would return -125.81
trunc(125.815, -1) would return 120
trunc(125.815, -2) would return 100
trunc(125.815, -3) would return 0