Oracle trunc 函式的用法

2021-06-25 17:08:04 字數 1415 閱讀 8942

--oracle trunc()函式的用法

/**************日期********************/

1.select trunc(sysdate) from dual  

--2011-3-18  今天的日期為2011-3-18

2.select trunc(sysdate, 'mm')   from   dual  

--2011-3-1    返回當月第一天.

3.select trunc(sysdate,'yy') from dual

--2011-1-1       返回當年第一天

4.select trunc(sysdate,'dd') from dual

--2011-3-18    返回當前年月日

5.select trunc(sysdate,'yyyy') from dual

--2011-1-1   返回當年第一天

6.select trunc(sysdate,'d') from dual

--2011-3-13 (星期天)返回當前星期的第一天

7.select trunc(sysdate, 'hh') from dual 

--2011-3-18 14:00:00   當前時間為14:41   

8.select trunc(sysdate, 'mi') from dual 

--2011-3-18 14:41: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

--014.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 函式的用法

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

oracle trunc 函式的用法

關於trunc函式的format,自己現在有點體會,format為day時,只精確到天,而不管幾年幾月只要是符合的day就可以了,要想確定一年中的某月的某一天就要用trunc date,dd 通俗的說吧,format為年時,精確到 年 為月時,精確到 年,月 不管哪年,只要是相同的月和哪天 為日時,...

Oracle trunc 函式的用法

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