如何在 current_timestamp SQL 中添加 10 秒(Oracle)
How to add 10 seconds in current_timestamp SQL ( Oracle )
我想在 PL/SQL 脚本中向 current_timestamp
添加 10 秒。我试过下面的代码,但它的输出不是时间戳格式。
SELECT CURRENT_TIMESTAMP+1/24/60/6 FROM dual;
输出:
CURRENT_TIMESTAMP+1/24/60/6
---------------------------
28-AUG-15
Mysql服务器有类似TIMESTAMPADD的功能吗?
在 Oracle 中,如果您想要 timestamp
作为结果,而不是 date
(不过,date
总是包括秒的时间,所以您可能只是想要一个 date
),你想要在 timestamp
中添加一个 interval
。有多种构造区间的方法——你可以使用区间文字
select current_timestamp + interval '10' second
from dual
或者您可以使用 numtodsinterval
函数
select current_timestamp + numToDSInterval( 10, 'second' )
from dual
使用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;
输出:
TIMESTAMP TIMESTAMP_PLUS_10SEC
31-08-15 05:17:19 31-08-15 05:17:29
我想在 PL/SQL 脚本中向 current_timestamp
添加 10 秒。我试过下面的代码,但它的输出不是时间戳格式。
SELECT CURRENT_TIMESTAMP+1/24/60/6 FROM dual;
输出:
CURRENT_TIMESTAMP+1/24/60/6
---------------------------
28-AUG-15
Mysql服务器有类似TIMESTAMPADD的功能吗?
在 Oracle 中,如果您想要 timestamp
作为结果,而不是 date
(不过,date
总是包括秒的时间,所以您可能只是想要一个 date
),你想要在 timestamp
中添加一个 interval
。有多种构造区间的方法——你可以使用区间文字
select current_timestamp + interval '10' second
from dual
或者您可以使用 numtodsinterval
函数
select current_timestamp + numToDSInterval( 10, 'second' )
from dual
使用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;
输出:
TIMESTAMP TIMESTAMP_PLUS_10SEC
31-08-15 05:17:19 31-08-15 05:17:29