Add days Oracle SQL

SqlOracle11g

Sql Problem Overview


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?

Sql Solutions


Solution 1 - Sql

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

SELECT ( SYSDATE + N ) FROM DUAL;

Solution 2 - Sql

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

order_date + 20

Solution 3 - Sql

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

  1. add a day

    select sysdate + INTERVAL '1' DAY from dual;

  2. add 20 days

    select sysdate + INTERVAL '20' DAY from dual;

  3. add some minutes

    select sysdate + INTERVAL '15' MINUTE from dual;

Solution 4 - Sql

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:

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

See also: NUMTODSINTERVAL in Oracle Database Online Documentation

Solution 5 - Sql

It's Simple.You can use

select (sysdate+2) as new_date from dual;

This will add two days from current date.

Solution 6 - Sql

One thing about select (sysdate+3) from dual is that the sysdate is interpreted as date.

But if you want to use a custom date, not local, you need to make sure it is interpreted as date, not string. Like so (adding 3 days):

select (to_date('01/01/2020')+3) from dual

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSQL_StudentView Question on Stackoverflow
Solution 1 - Sqlmkumawat10View Answer on Stackoverflow
Solution 2 - SqlMikeView Answer on Stackoverflow
Solution 3 - SqlFrancesco SerraView Answer on Stackoverflow
Solution 4 - SqlMichael KremserView Answer on Stackoverflow
Solution 5 - SqlshahView Answer on Stackoverflow
Solution 6 - SqlRaffyTaffyView Answer on Stackoverflow