Oracle SQL Syntax: Quoted identifier

Will picture Will · Jun 24, 2011 · Viewed 9.7k times · Source

I encountered SQL queries that looked like

select "hello"
from "foo"."bar"

I found that we can have quoted and unquoted identifiers in Oracle: Database Object Names and Qualifiers

... A quoted identifier begins and ends with double quotation marks ("). If you name a schema object using a quoted identifier, then you must use the double quotation marks whenever you refer to that object...

I asked the DBAs and they told me that there is a table with name bar but not "bar"

Why is that?

Answer

Tony Andrews picture Tony Andrews · Jun 24, 2011

The table is named bar and not BAR or "bar" but because it is in lowercase you can only reference it using double quotes:

select * from bar; -- will fail

select * from "bar"; -- will succeed

The moral is: never create tables like this!