oracle提供內建函式:numtodsinterval(<x>,<c>) , x是一個數字,加減值,可以為小數和分數,如1,1/2, 0.05 c是一個字串,為加減單位 , 常用的單位有 ('day','hour','minute','second')表明x的單位,這個函數把x轉為interval day to second資料類型
------------------------------------------------------------------------------------
example
SQL> select sysdate,sysdate+numtodsinterval(3,'hour') as res from dual;
SYSDATE RES
------------------- -------------------
2007-09-05 01:45:34 2007-09-05 04:45:34
numtoyminterval 與numtodsinterval函數類似,將x轉為interval year to month資料類型 常用的單位有'year','month' example SQL> select sysdate,sysdate+numtoyminterval(3,'year') as res from dual; SYSDATE RES
------------------- -------------------
2007-09-05 01:54:53 2010-09-05 01:54:53
================================ 測試sql select systimestamp, systimestamp+NUMTODSINTERVAL(0.5,'SECOND'), systimestamp+NUMTODSINTERVAL(0.05,'SECOND') from dual;