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

前端 未结 2 1324
粉色の甜心
粉色の甜心 2021-01-21 02:39

In my Oracle DB setup all the tables are created under dedicated user account SYS0MYUSER. When executing following query on my system I got SQL Error: ORA-009

相关标签:
2条回答
  • 2021-01-21 03:17
    SELECT COUNT(*) FROM "SYS0MYUSER"."USER";
    
    0 讨论(0)
  • 2021-01-21 03:19

    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>
    
    0 讨论(0)
提交回复
热议问题