Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly do quotation marks around the table name do?

Tags:

sql

oracle

I thought that the quotation mark (") was simply a type of grouping marker but I'm debugging some NHibernate code and notice that while

SELECT * FROM site WHERE site_id = 3; 

Works fine

SELECT * FROM "site" WHERE site_id = 3; 

fails with a table or view does not exist error.

What gives?

like image 214
George Mauer Avatar asked Feb 18 '09 22:02

George Mauer


People also ask

What do quotation marks around a name mean?

8 years ago. 18 Comments. by Stan Carey. Quotation marks, also known as inverted commas, are normally used for quotation, as their American name suggests, or to mark a title (book, film, etc), or to enclose a foreign, technical, or otherwise potentially unfamiliar word.

What do quotation marks show?

We use quotation marks to show (or mark) the beginning and end of a word or phrase that is somehow special or comes from outside the text that we are writing.

Do you use quotation marks for names of things?

In general, you should italicize the titles of long works, like books, movies, or record albums. Use quotation marks for the titles of shorter pieces of work: poems, articles, book chapters, songs, T.V.


2 Answers

Putting double-quotes around an identifier in Oracle causes Oracle to treat the identifier as case sensitive rather than using the default of case-insensitivity. If you create a table (or a column) with double-quotes around the name, you must always refer to the identifier with double quotes and by correctly specifying the case (with the exception of all upper case identifiers, where double-quotes are meaningless).

Under the covers, Oracle is always doing case-sensitive identifier matching. But it always casts identifiers that are not double-quoted to upper case before doing the matching. If you put double-quotes around an identifier, Oracle skips the casting to upper case.

So if you do something like

CREATE TABLE my_table(    col1 number,   col2 number ) 

you can

SELECT * FROM my_table SELECT * FROM MY_TABLE SELECT * FROM My_Table SELECT * FROM "MY_TABLE" 

but something like

SELECT * FROM "my_table"  

will fail.

On the other hand, if you do something like

CREATE TABLE "my_other_table"(    col1 number,   col2 number ) 

you cannot do

SELECT * FROM my_other_table SELECT * FROM MY_OTHER_TABLE SELECT * FROM My_Other_Table SELECT * FROM "MY_OTHER_TABLE" 

but this

SELECT * FROM "my_other_table"  

will work

like image 132
Justin Cave Avatar answered Sep 28 '22 03:09

Justin Cave


It should be added that identifiers in quotation marks may contain special characters, e.g. "a-b c.d" is a valid identifier.

like image 42
Erich Kitzmueller Avatar answered Sep 28 '22 03:09

Erich Kitzmueller