Oracle trunc 函式的用法

2022-09-04 15:21:34 字數 539 閱讀 2670

1.日期處理:

trunc(date,' x ');

x為日期格式,例如『hh』是小時,『yyyy』是年,『mm』是月份,預設為當前日的零點

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

trunc('時間','時間對應的位置'),比如『mm』對應的是月份,『dd』對應的是哪一天,『hh24』返回當前日期,精確到小時,『mi』就精確到分鐘,最多就到分鐘數,沒有『ss』;

2.數值處理:

trunc(number, x );

x為數值型別,例如數值為2就是取小數點後兩位,沒有四捨五入的功能,x預設為0。

select trunc(123.456,2) from dual; --123.45(就不會四捨五入)。

四捨五入的函式為round.

select round(123.456,2) from dual;--123.46(四捨五入取法)。

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...