添加天 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
Add days Oracle SQL
提问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
回答by shah
It's Simple.You can use
很简单,你可以用
select (sysdate+2) as new_date from dual;
This will add two days from current date.
这将从当前日期增加两天。