How can I add seconds with timestamp value in Oracle. I tried this ....
SELECT CURRENT_TIMESTAMP , CURRENT_TIMESTAMP+200 AS addedTime FROM dual
But by this I am getting this
2018-06-04 19:03:01 => 2018-12-21 19:03:01 (after adding 200)
As you can see date is getting added , but I want to add second only...
This SQL running properly in DB2 , can any one suggest me any suitable alternative in Oracle.
In Oracle date/time arithmetic is expressed in terms of days. So adding
200
adds 200 days to an OracleDATE
orTIMESTAMP
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 orADD_MONTHS()
(interval months and years are particularly dangerous as they are not leap-year safe, whileADD_MONTHS()
is).Note that the single quotes around the interval value are necessary;
INTERVAL 200 SECOND
will raise an error.Hope this helps.
You could always use fraction(for Oracle 1 = 1 day):
DBFiddle Demo
or: