如何在 current_timestamp SQL ( Oracle ) 中添加 10 秒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32277369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:00:27  来源:igfitidea点击:

How to add 10 seconds in current_timestamp SQL ( Oracle )

sqloracletimestamp

提问by Nagendra Yadav

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

我想current_timestamp在我的 PL/SQL 脚本中添加 10 秒。我尝试了下面的代码,但它的输出不是时间戳格式。

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?

Mysql服务器中是否有类似于TIMESTAMPADD的功能?

回答by Justin Cave

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

在 Oracle 中,如果您想要 atimestamp作为结果,而不是 a datedate不过,a总是包含到秒的时间,因此您可能只想要 a date),您需要将 an 添加intervaltimestamp. 有多种构造区间的方法——您可以使用区间文字

select current_timestamp + interval '10' second
  from dual

or you could use the numtodsintervalfunction

或者你可以使用这个numtodsinterval功能

select current_timestamp + numToDSInterval( 10, 'second' )
  from dual

回答by mahi_0707

It can be achieved by using TO_CHAR

它可以通过使用来实现 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