20

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.

bonsvr
  • 2,262
  • 5
  • 22
  • 33
  • paste your 'desc calendars' please – KevinDTimm Oct 20 '11 at 21:19
  • It *really* should be valid to use (any) reserved word as a column name as `"date"` or `[date]` (but perhaps the latter is TSQL?), but I don't use Oracle so... perhaps the schema is not as expected? –  Oct 20 '11 at 21:19
  • (BTW, try as I might, I can't even create a table in oracle with a column named date) – KevinDTimm Oct 20 '11 at 21:30
  • yes but you can --> create table a ("DATE" date), if you want to make the table user suffer :) – bonsvr Oct 20 '11 at 21:36

3 Answers3

23

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;
Community
  • 1
  • 1
FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202
  • it gives ORA-01747 error when I add the table name or alias. I didnt try to drop the column but there is no problem with select * from calendars. So I dont need to drop the column if any further action wouldnt be taken. – bonsvr Oct 20 '11 at 21:18
  • 3
    select "DATE" from calendars solved it. It was DATE, not date. – bonsvr Oct 20 '11 at 21:31
10

Try escaping the reserved word with double quotes.

select "date" from calendars
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
1

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

Ankit Suhail
  • 2,045
  • 21
  • 32