The TRUNC function in Oracle is used to truncate the specified part of the date or number. It supports the following units: year, month, date, hour, minute, second. The syntax is TRUNC(expression, unit), expression is the expression to be truncated, and unit is the unit to be truncated.
Usage of TRUNC function in Oracle
Brief Overview
TRUNC Function used in Oracle to truncate a specified portion from a date or number.
Syntax
<code>TRUNC(<expression>, <unit>)</code>
Parameters
unit: The unit to be truncated, which can be:
Return value
The TRUNC function returns a truncated value whose type is the same as the expression.
Usage
Truncate date
<code>SELECT TRUNC(sysdate, 'YEAR') FROM dual; -- 返回当前年份,如 2023</code>
Truncate number
<code>SELECT TRUNC(123.456, 2) FROM dual; -- 返回截断到小数点后两位的数字,如 123.45</code>
Truncation combination
<code>SELECT TRUNC(sysdate, 'DAY TO SECOND') FROM dual; -- 返回当前日期和时间,截断到秒</code>
Notes
The above is the detailed content of Usage of trunc function in oracle. For more information, please follow other related articles on the PHP Chinese website!