ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" *Cause: *Action:

497 views Asked by At

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

There are 2 answers

0
Ansar Nawaz On

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
0
Popeye On

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;