how to add second in oracle timestamp

大城市里の小女人 提交于 2019-11-29 16:35:17

You could always use fraction(for Oracle 1 = 1 day):

SELECT CURRENT_TIMESTAMP ,
       CURRENT_TIMESTAMP + 200 *(1/24/60/60) AS addedTime 
FROM dual;
<=>
SELECT CURRENT_TIMESTAMP + 200/86400 FROM dual

DBFiddle Demo

or:

SELECT CURRENT_TIMESTAMP + INTERVAL '200' SECOND FROM dual

In Oracle date/time arithmetic is expressed in terms of days. So adding 200 adds 200 days to an Oracle DATE or TIMESTAMP object. If you want to add seconds you can either use intervals or you can add fractional days. Personally, for something as granular as seconds I prefer to use intervals; anything from hours and up I use regular date arithmetic or ADD_MONTHS() (interval months and years are particularly dangerous as they are not leap-year safe, while ADD_MONTHS() is).

SELECT CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + INTERVAL '200' SECOND FROM dual;

Note that the single quotes around the interval value are necessary; INTERVAL 200 SECOND will raise an error.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!