在10g以前,ALL_SYNONYMS视图可能会缺少指向同义词的同义词。
看一个具体的例子:
SQL> conn u1/u1@test9i
Connected.
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
PL/SQL Release 9.2.0.4.0 - Production
CORE 9.2.0.3.0 Production
TNS for Linux: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production
SQL> create table t (id number);
Table created.
SQL> grant select on t to u2;
Grant succeeded.
SQL> create synonym s1 for t;
Synonym created.
SQL> create synonym s2 for s1;
Synonym created.
SQL> select owner, synonym_name, table_owner, table_name
2 from all_synonyms
3 where owner = user;
OWNER SYNONYM_NAME TABLE_OWNE TABLE_NAME
---------- ------------------------------ ---------- ------------------------------
U1 S1 U1 T
U1 S2 U1 S1
SQL> conn u2/u2@test9i
Connected.
SQL> select count(*) from u1.t;
COUNT(*)
----------
0
SQL> select count(*) from u1.s1;
COUNT(*)
----------
0
SQL> select count(*) from u1.s2;
COUNT(*)
----------
0
SQL> select owner, synonym_name, table_owner, table_name
2 from all_synonyms
3 where owner = 'U1';
OWNER SYNONYM_NAME TABLE_OWNE TABLE_NAME
---------- ------------------------------ ---------- ------------------------------
U1 S1 U1 T
可以看到,这个例子中,U1用户可以看到自己创建的所有同义词,但是U2在ALL_SYNONYMS视图中看不到执行同义词的同义词S2,但是U2访问这个同义词并没有问题。
这个问题在10g中已经被解决:
SQL> conn u1/u1
Connected.
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL> create table t (id number);
Table created.
SQL> create synonym s1 for t;
Synonym created.
SQL> create synonym s2 for s1;
Synonym created.
SQL> select owner, synonym_name, table_owner, table_name
2 from all_synonyms
3 where owner = user;
OWNER SYNONYM_NAME TABLE_OWNE TABLE_NAME
---------- ------------------------------ ---------- ------------------------------
U1 S1 U1 T
U1 S2 U1 S1
SQL> grant select on t to u2;
Grant succeeded.
SQL> conn u2/u2
Connected.
SQL> select count(*) from u1.t;
COUNT(*)
----------
0
SQL> select count(*) from u1.s1;
COUNT(*)
----------
0
SQL> select count(*) from u1.s2;
COUNT(*)
----------
0
SQL> select owner, synonym_name, table_owner, table_name
2 from all_synonyms
3 where owner = 'U1';
OWNER SYNONYM_NAME TABLE_OWNE TABLE_NAME
---------- ------------------------------ ---------- ------------------------------
U1 S1 U1 T
U1 S2 U1 S1
显然10.2中已经fixed了这个bug。关于这个bug的详细描述,可以参考Bug 3369744。