如何在 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
How to add 10 seconds in current_timestamp SQL ( Oracle )
提问by Nagendra Yadav
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.
我想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 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
在 Oracle 中,如果您想要 atimestamp
作为结果,而不是 a date
(date
不过,a总是包含到秒的时间,因此您可能只想要 a date
),您需要将 an 添加interval
到timestamp
. 有多种构造区间的方法——您可以使用区间文字
select current_timestamp + interval '10' second
from dual
or you could use the numtodsinterval
function
或者你可以使用这个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