When I enter a dateadd or datediff code i get this error all the time “ORA-00904 ”DATEADD“ INVALID IDENTIFIER.”

落花浮王杯 提交于 2019-12-24 03:24:15

问题


I have a university project and I have a patient table with admission and discharge date attributes. I need to delete records that are older than 7 years, I used the following code :

delete from patient
where dis_date >= datedadd(yy,-7,getdate());

I get the error

"ORA-00904: "DATEADD" invalid identifier"

. It's the same with the DATEDIFF function. Any alternatives please?


回答1:


The typical way of doing this in Oracle would be:

DELETE FROM patient
 WHERE dis_date < TRUNC(ADD_MONTHS(SYSDATE, -7*12));

The reason I suggest using ADD_MONTHS() instead of year intervals is that ADD_MONTHS() is leap-year safe.




回答2:


You may try this:

DELETE FROM patient
  WHERE dis_date  < SYSDATE - INTERVAL '7' YEAR;

There is no function named as DATEADD in Oracle.



来源:https://stackoverflow.com/questions/29145825/when-i-enter-a-dateadd-or-datediff-code-i-get-this-error-all-the-time-ora-00904

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!