oracle中那个日期怎么相减_oracle数据库中日期加减函数
1.oracle中當(dāng)前系統(tǒng)時間加減用法
select add_months(sysdate, 12) "NEW YEAR" from dual; /**系統(tǒng)時間+12個月后的時間**/
select extract(month from sysdate) "This Month" from dual; /**獲取系統(tǒng)時間所在月份**/
select (sysdate + 1) "NEW DATE" from dual; /**系統(tǒng)時間+1天后的時間**/
2.下面一日期處理函數(shù)為網(wǎng)上看到一并寫在這里
create or replace function DATEADD(datepart varchar2,
num number,
indate date) return date is
Result date;
v_sql varchar2(1000);
v_datepart varchar2(30);
v_ms varchar2(13);
begin
v_datepart := lower(datepart);
/*
Datepart Abbreviations
year yy, y
quarter qq, q
month mm, m
day dd, d
week wk, w
hour hh, h
minute mi, n
second ss, s
millisecond ms
*/
case
when v_datepart in ('year', 'yy', 'y') then
v_sql := 'select :1 + interval ''' || num || ''' year from dual';
when v_datepart in ('quarter', 'qq', 'q') then
v_sql := 'select :1 + (interval ''3'' month) * ' || num ||
' from dual';
when v_datepart in ('month', 'mm', 'm') then
v_sql := 'select :1 + interval ''' || num || ''' month from dual';
when v_datepart in ('week', 'wk', 'w') then
v_sql := 'select :1 + (interval ''7'' day) * ' || num || ' from dual';
when v_datepart in ('day', 'dd', 'd') then
v_sql := 'select :1 + interval ''' || num || ''' day from dual';
when v_datepart in ('hour', 'hh') then
v_sql := 'select :1 + interval ''' || num || ''' hour from dual';
when v_datepart in ('minute', 'mi', 'n') then
v_sql := 'select :1 + interval ''' || num || ''' minute from dual';
when v_datepart in ('second', 'ss', 's') then
v_sql := 'select :1 + interval ''' || num || ''' second from dual';
when v_datepart in ('millisecond', 'ms') then
v_ms := to_char(num / 1000, 'fm999999990.000');
v_sql := 'select :1 + interval ''' || v_ms ||
''' second(9,3) from dual';
else
RAISE_APPLICATION_ERROR(-20001,
'''' || datepart ||
''' is not a recognized dateadd option.');
end case;
execute immediate v_sql
into Result
using indate;
return(Result);
EXCEPTION
WHEN OTHERS THEN
RAISE;
end DATEADD;
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的oracle中那个日期怎么相减_oracle数据库中日期加减函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 农夫山泉被指虚假宣传 官方回应:在海拔高
- 下一篇: gnotify.exe是什么进程 有什么