Skip to content Skip to sidebar Skip to footer

How Can I Select A Column Named 'date' In Oracle?

I have a problem with SELECT query in ORACLE SQL. There is a table named 'Battles' with columns 'name' and 'date'. When I try to do: SELECT date FROM Battles - there is an error:

Solution 1:

Yes you guessed it correct. date is a reserve word in Oracle (in fact it's a datatype) and you should escape it using double quote "" like below.

SELECT "date" FROM Battles

That's the very same reason you should never choose column/table names to be reserve word. Even though almost all the RDBMS provides a way/mechanism to bypass this but it's a never a good practice.

Solution 2:

In order to quote a identifier, Oracle uses the double quotes. Be aware, that this also makes them case sensitive (you said the column is named date in lowercase, so):

select"date"from Battles;

See Quoted Identifiers in the Oracle Doc.

Post a Comment for "How Can I Select A Column Named 'date' In Oracle?"