The TRUNC function is used to truncate a value.
There are two usages: TRUNC(NUMBER) to truncate numbers, and TRUNC(date) to truncate dates.
Get the first day of the previous month:
SQL> select TRUNC(add_months(SYSDATE,-1),'MM') from dual
===================================================================
--Usage of Oracle trunc() function
/****************Date********************/
1.select trunc (sysdate) from dual --2011-3-18 Today's date is 2011-3-18
2.select trunc(sysdate, 'mm') from dual --2011-3-1 returns the first day of the current month.
3.select trunc(sysdate,'yy') from dual --2011-1-1 returns the first day of the
current year4.select trunc(sysdate,'dd') from dual --2011-3-18 returns the current year month
day5.select trunc(sysdate,'yyyy') from dual --2011-1-1 returns the first day of the current year
6.select trunc(sysdate,'d') from dual --2011-3-13 (Sunday) returns the first day of the current week One day
7.select trunc(sysdate, 'hh') from dual --2011-3-18 14:00:00 The current time is 14:41
8.select trunc(sysdate, 'mi') from dual --2011- 3-18 14:41:00 TRUNC() function has no second precision
/****************Number********************/
/*
TRUNC(number,num_digits)
Number needs to be truncated Rounded number.
Num_digits Numbers used to specify rounding precision. The default value of Num_digits is 0.
TRUNC() function does not round off when intercepting
*/
9.select trunc(123.458) from dual --123
10.select trunc(123.458,0) from dual --123
11.select trunc(123.458,1) from dual -- 123.4
12.select trunc(123.458,-1) from dual --120
13.select trunc(123.458,-4) from dual --0
14.select trunc(123.458,4) from dual --123.458
15.select trunc( 123) from dual --123
16.select trunc(123,1) from dual --123
17.select trunc(123,-1) from dual --120