为什么我必须双重引用模式名称和表名才能从Oracle表中查询?

时间:2012-08-17 06:48:53

标签: oracle

我是Oracle的新手,我遇到了以下问题。为什么我必须双重引用模式名称和表名才能从表中查询?有没有改变它的设置?

感谢。

SQL> conn sys/ogrish@orcl as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

SQL> select * from m.album;
select * from m.album
                *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from M.Album where rownum < 2;
select * from M.Album where rownum < 2;
              *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select * from "M"."Album" where rownum < 2;

   AlbumId Title
---------- ----------------------------------------------------------------------
         1 For Those About To Rock We Salute You

SQL> conn m/m@orcl
Connected.
SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
Album
Artist
Customer
Employee
Genre
Invoice
InvoiceLine
MediaType
Playlist
PlaylistTrack
sysdiagrams

TABLE_NAME
------------------------------
Track

12 rows selected.

SQL> select * from album where rownum < 2;
select * from album where rownum < 2;
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from Album where rownum < 2;
select * from Album where rownum < 2
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from m.album where rownum < 2;
select * from m.album where rownum < 2
                *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from M.Album where rownum < 2;
select * from M.Album where rownum < 2
                *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "M"."Album" where rownum < 2;

   AlbumId Title
---------- ----------------------------------------------------------------------
         1 For Those About To Rock We Salute You

SQL> select * from "Album" where rownum < 2;

   AlbumId Title
---------- ----------------------------------------------------------------------
         1 For Those About To Rock We Salute You

SQL>

2 个答案:

答案 0 :(得分:5)

您不必在架构名称上添加双引号,但是您必须在表名称上执行此操作,因为您使用引号创建了它(使其区分大小写):

select * from M."Album"

也应该有用。否则,M.Album默认翻译为M.ALBUM - 并且表ALBUM不存在。

答案 1 :(得分:0)

您可以避免使用同义词预先修复架构名称。