添加天 Oracle SQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27451226/
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 03:03:47  来源:igfitidea点击:

Add days Oracle SQL

sqloracle11g

提问by SQL_Student

SELECT ORDER_NUM, CUSTOMER_NUM, CUSTOMER_NAME, ADD_DAYS (ORDER_DATE, 20)
FROM CUSTOMER, ORDERS; 

Oracle Express says ADD_DAYS invalid? Any ideas what Am I doing wrong?

Oracle Express 说 ADD_DAYS 无效?任何想法我做错了什么?

回答by mkumawat10

If you want to add N days to your days. You can use the plus operator as follows -

如果您想在您的天数中添加 N 天。您可以按如下方式使用加号运算符 -

SELECT ( SYSDATE + N ) FROM DUAL;

回答by Mike

You can use the plus operator to add days to a date.

您可以使用加号运算符为日期添加天数。

order_date + 20

回答by Francesco Serra

In a more general way you can use "INTERVAL". Here some examples:

以更一般的方式,您可以使用“INTERVAL”。这里有一些例子:

1) add a day

1)增加一天

select sysdate + INTERVAL '1' DAY from dual;

2) add 20 days

2) 增加 20 天

select sysdate + INTERVAL '20' DAY from dual;

2) add some minutes

2)添加一些分钟

select sysdate + INTERVAL '15' MINUTE from dual;

回答by Michael Kremser

Some disadvantage of "INTERVAL '1' DAY" is that bind variables cannot be used for the number of days added. Instead, numtodsinterval can be used, like in this small example:

“INTERVAL '1' DAY”的一些缺点是绑定变量不能用于添加的天数。相反,可以使用 numtodsinterval,就像在这个小例子中一样:

select trunc(sysdate) + numtodsinterval(:x, 'day') tag
from dual

See also: NUMTODSINTERVAL in Oracle Database Online Documentation

另请参阅:Oracle 数据库在线文档中的 NUMTODSINTERVAL

回答by shah

It's Simple.You can use

很简单,你可以用

select (sysdate+2) as new_date from dual;

This will add two days from current date.

这将从当前日期增加两天。