views:

1617

answers:

4

In TSQL I could use something like Select [table] from tablename to select a column named "table".

How do I do this for reserved words in oracle?

Edit: I've tried square braces, double quotes, single quotes, and backquotes, they don't work...

As a further clarification, I have a column which someone named comment. As this is a reserved word oracle is chucking a wobbly trying to select with it, its failing when parsing the query. I've tried Select "comment" from tablename but it didn't work. I'll check case and come back.

+9  A: 

From a quick search, Oracle appears to use double quotes (", eg "table") and apparently requires the name to be fully qualified and the correct case—whereas, for anyone interested, MySQL defaults to using backtics (`) except when set to use double quotes for compatibility.

eyelidlessness
Hey, I could be wrong, but could the person who knew I was wrong post the right answer?
eyelidlessness
I marked you down because I tried to escape the word using double quotes and it didn't work.
Spence
I'll double check everything and come back and mark you right if I get it to work with double quotes.
Spence
Could you edit your answer for prosperity to add that you have to fully qualify the name AND get the case right.
Spence
A: 

Oracle does use double-quotes, but you most likely need to place the object name in upper case, e.g. "TABLE". By default, if you create an object without double quotes, e.g.

CREATE TABLE table AS ...

Oracle would create the object as upper case. However, the referencing is not case sensitive unless you use double-quotes!

Andrew from NZSG
+2  A: 

eyelidlessness (huh??) was correct regarding the double quotes.

However if quoted names are use, Oracle is case-sensitive (and typically Oracle names are all-uppercase).

devio
Case caught me out, so +1
Spence
From a particular translation of a work by Sartre. Haven't been able to track it down myself.
eyelidlessness
+2  A: 

Oracle normally requires double-quotes to delimit the name of identifiers in SQL statements, e.g.

SELECT "MyColumn" AS "MyColAlias"
FROM "MyTable" AS "Alias"
WHERE "ThisCol" = 'That Value';

However, it graciously allows omitting the double-quotes, in which case it quietly converts the identifier to uppercase:

SELECT MyColumn AS MyColAlias
FROM MyTable AS Alias
WHERE ThisCol = 'That Value';

gets internally converted to something like:

SELECT "MYTABLE" . "MYCOLUMN" AS "MYCOLALIAS"
FROM "THEUSER" . "MYTABLE" AS "ALIAS"
WHERE "MYTABLE" . "THISCOL" = 'That Value';
Jeffrey Kemp