0

Sorry if my question sounds dumb but I'm relatively new to coding especially in Oracle SQL Developer and really need help. I used to use mySQL. So I'm still a little confused.

Here is my code:

CREATE VIEW ViewC AS
SELECT * FROM watermeter
WHERE deployeddate <= dateadd(month,-6, getdate()) AND
deployeddate  > CURRENT_DATE();

The code error:

Error starting at line : 1 in command -
CREATE VIEW ViewC AS
SELECT * FROM watermeter
WHERE deployeddate <= dateadd(month,-6, getdate()) AND
deployeddate  > CURRENT_DATE()
Error report -
ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:

In case you wanna know, the question is: List the meters that are due for replacement in the next six months (this view should be able to work at any time in the future without needing to be changed to accommodate the date).

2 Answers 2

1

Dateadd is not oracle function. And for today's date, you can use sysdate.

You can use the following code:

CREATE VIEW ViewC AS
SELECT * FROM watermeter
WHERE deployeddate <= add_months(sysdate , -6) AND
deployeddate  > sysdate;
Sign up to request clarification or add additional context in comments.

Comments

0

There isn't any function like Dateadd in Oracle. You can use

SYSDATE     
SYSTIMESTAMP
TO_CHAR     
TO_DATE     

SELECT SYSTIMESTAMP FROM dual;      

OUTPUT: 01-AUG-17 01.33.57.929000000 PM -07:00

TO_CHAR( DATE'2017-01-01', 'DL' )

    OUTPUT: Sunday, January 01, 2017

TO_DATE( '01 Jan 2017', 'DD MON YYYY' )

OUTPUT: 01-JAN-17

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.