同义词和已存在的表同名
时间:2010-11-25 来源:lovegigi1999
我们都知道通过访问同义词就相当于访问其他schema对象的表,但是有一种情况要注意,那就是当你创建的同义词和其他对象重名的时候,有可能你执行同义词查询却指向了另一个同名的对象,导致无法访问到正确的数据。
看如下测试:
sys@FOX> create table s_a (name varchar2(10));
Table created.
sys@FOX> create public synonym s_a for t1;
Synonym created.
sys@FOX> select * from s_a;
no rows selected
sys@FOX> select * from t1;
X
----------
2
2
2
2
sys@FOX> select owner,object_name,object_type FROM dba_objects where object_name='S_A';
OWNER OBJECT_NAME OBJECT_TYPE
------------------------------ ---------------------------------------- ------------------
PUBLIC S_A SYNONYM
SCOTT S_A TABLE
看如下测试:
sys@FOX> create table s_a (name varchar2(10));
Table created.
sys@FOX> create public synonym s_a for t1;
Synonym created.
sys@FOX> select * from s_a;
no rows selected
sys@FOX> select * from t1;
X
----------
2
2
2
2
sys@FOX> select owner,object_name,object_type FROM dba_objects where object_name='S_A';
OWNER OBJECT_NAME OBJECT_TYPE
------------------------------ ---------------------------------------- ------------------
PUBLIC S_A SYNONYM
SCOTT S_A TABLE
相关阅读 更多 +