oracle 同义词实例

现有user1和user2两个用户,将在user2上创建user1的table1的同义词,然后就可以使用user2直接查询该同义词,获得user1的table1的数据。

1、使用user1连接,使user2获得user1的table1的查询权限:

     grant select on table1 to user2;

2、使用user2连接,创建同义词

     create or replace public synonym syn_table1 for user1.table1;

     现在可查询该同义词是否建立成功:

     select * from dba_synonyms where table_owner = 'USER1';

     接下来可以直接在user2中查询该同义词的数据:

     select * from syn_table1;

3、使用user2连接,删除同义词

     drop public synonym synoonsyn_table1;

4、使用user1连接,移除table1上的user2查询权限

     revoke select on table1 from user2;

5、查询同义词表的列信息

     select b.synonym_name as table_name, a.column_name, a.data_type as type_name, 

               decode (a.data_precision, null, a.data_length, a.data_precision) as column_size, 

               a.column_id AS ordinal_position

       from all_tab_columns a, syn b

    where a.owner = b.table_owner and a.table_name = b.table_name and b.synonym_name = 'SYN_TABLE1';

猜你喜欢

转载自jerry-chen.iteye.com/blog/1463827
今日推荐