Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add 10 seconds in current_timestamp SQL ( Oracle )

Tags:

I want to add 10 seconds to current_timestamp in my PL/SQL script. I tried below code but it's output is not in timestamp format.

SELECT CURRENT_TIMESTAMP+1/24/60/6 FROM dual; 

Output:

CURRENT_TIMESTAMP+1/24/60/6  --------------------------- 28-AUG-15 

Is there any function similar to TIMESTAMPADD in Mysql server?

like image 376
Nagendra Yadav Avatar asked Aug 28 '15 18:08

Nagendra Yadav


People also ask

How do I add a TIMESTAMP in Oracle?

You can use the below code: insert into tablename (timestamp_value) values (TO_TIMESTAMP(:ts_val, 'YYYY-MM-DD HH24:MI:SS')); If you need the current timestamp to be inserted then use the following code: insert into tablename (timestamp_value) values (CURRENT_TIMESTAMP);

How do I show minutes and seconds in SQL Developer?

Or do this : alter session set nls_date_format = 'yyyy/mm/dd hh24:mi:ss';

Does Oracle date have milliseconds?

Dates do not contain milliseconds, they only go as fine as seconds. You might want to try a timestamp datatype. Valid date range from January 1, 4712 BC, to December 31, 9999 AD. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter.


2 Answers

In Oracle, if you want a timestamp as the result, rather than a date (a date always includes the time to the second, though, so you may just want a date), you'd want to add an interval to the timestamp. There are various ways to construct an interval-- you can use an interval literal

select current_timestamp + interval '10' second   from dual 

or you could use the numtodsinterval function

select current_timestamp + numToDSInterval( 10, 'second' )   from dual 
like image 70
Justin Cave Avatar answered Sep 28 '22 04:09

Justin Cave


It can be achieved by using TO_CHAR

Select TO_CHAR(current_timestamp,'DD-MM-YY hh24:mi:SS') AS TIMESTAMP, TO_CHAR(current_timestamp+10/24/60/60,'DD-MM-YY hh24:mi:SS') AS TIMESTAMP_PLUS_10SEC from dual; 

OUTPUT:

   TIMESTAMP         TIMESTAMP_PLUS_10SEC 31-08-15 05:17:19     31-08-15 05:17:29 
like image 41
mahi_0707 Avatar answered Sep 28 '22 02:09

mahi_0707