How do I use quoted identifier for user + table name combination in Oracle?

一曲冷凌霜 提交于 2019-12-01 20:48:55

If you have created the table using quoted identifier, then you must always use double-quotation marks wherever you refer the object.

From documentation,

Database Object Naming Rules

Every database object has a name. In a SQL statement, you represent the name of an object with a quoted identifier or a nonquoted identifier.

  • 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.

  • A nonquoted identifier is not surrounded by any punctuation.

For example,

SQL> CREATE TABLE "USER"(A NUMBER);

Table created.

SQL>
SQL> SELECT COUNT(*) FROM LALIT.USER;
SELECT COUNT(*) FROM LALIT.USER
                           *
ERROR at line 1:
ORA-00903: invalid table name


SQL>
SQL> SELECT COUNT(*) FROM LALIT."USER";

  COUNT(*)
----------
         0

SQL>

So, you need to refer the table as a quoted identifier:

SELECT COUNT(*) FROM SYS0MYUSER."USER";

Update OP updated his question regarding table alias.

What's about table alias do I have to use double quotes too ?

Table alias has nothing to do with the quoted identifier.

For example,

SQL> SELECT t.* FROM LALIT."USER" t;

no rows selected

SQL>
SELECT COUNT(*) FROM "SYS0MYUSER"."USER";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!