Oracle trunc函式用法

2021-07-10 17:46:51 字數 1234 閱讀 3056

--日期

1.select trunc(sysdate) from dual --2013-01-06 今天的日期為2013-01-06

2.select trunc(sysdate, 'mm') from dual --2013-01-01 返回當月第一天.

3.select trunc(sysdate,'yy') from dual --2013-01-01 返回當年第一天

4.select trunc(sysdate,'dd') from dual --2013-01-06 返回當前年月日

5.select trunc(sysdate,'yyyy') from dual --2013-01-01 返回當年第一天

6.select trunc(sysdate,'d') from dual --2013-01-06 (星期天)返回當前星期的第一天

7.select trunc(sysdate, 'hh') from dual --2013-01-06 17:00:00 當前時間為17:35

8.select trunc(sysdate, 'mi') from dual --2013-01-06 17:35:00 trunc()函式沒有秒的精確

--數字

/*trunc(number,num_digits)

number 需要截尾取整的數字。

num_digits 用於指定取整精度的數字。num_digits 的預設值為 0。

trunc()函式擷取時不進行四捨五入

*/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

ORACLE TRUNC函式用法

1.trunc for dates trunc函式為指定元素而截去的日期值。其具體的語法格式如下 trunc date fmt 其中 date 乙個日期值 fmt 日期格式,該日期將由指定的元素格式所截去。忽略它則由最近的日期截去 下面是該函式的使用情況 trunc to date 24 nov 1...

Oracle trunc 函式用法

oracle trunc 函式的用法 日期 1.select trunc sysdate from dual 2013 01 06 今天的日期為2013 01 06 2.select trunc sysdate,mm from dual 2013 01 01 返回當月第一天.3.select tru...

oracle trunc函式用法

1.trunc for dates trunc函式為指定元素而截去的日期值。其具體的語法格式如下 trunc date fmt 其中 date 乙個日期值 fmt 日期格式,該日期將由指定的元素格式所截去。忽略它則由最近的日期截去 2.trunc for number trunc函式返回處理後的數值...