“date” as a column name

我怕爱的太早我们不能终老 提交于 2019-12-06 18:46:29

问题


I have a table called calendars.

One of its columns is named 'date'

When I want to select the date column it gives error ORA-01747 namely invalid table.column.

select date from calendars

I guess this happens because 'date' is a reserved word for pl/sql. The problem is it's not even possible to change the column name :

alter table calendars rename column date to date_d

Result is: ORA-00904 error: invalid identifier.

What do you advice?

Thanks.


回答1:


Have you tried

select calendars.date from calendars; /* or you could alias "calendars" if you don't want to type so much */

If that doesn't work or help, have you tried dropping the column (and maybe try referencing it with the table name prefix: calendars.date)?


I also found this post: How do I escape a reserved word in Oracle?

It seems that Oracle will be case-sensitive if you use double quotes so

select "date" from calendars;

is not the same as

select "Date" from calendars;



回答2:


Try escaping the reserved word with double quotes.

select "date" from calendars



回答3:


date is a reserved keyword and hence cannot be used like

SELECT date from some table

there can be multiple solutions for the problem

  • The date column needs to be enclosed within the brackets like

SELECT [date] FROM tableName

  • Enclose the reserved keyword in backticks

SELECT 'date' from tableName

  • Use alias

SELECT tableName.date from tableName



来源:https://stackoverflow.com/questions/7842262/date-as-a-column-name

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