1:以sysdba登陆系统,首先创建一个用户
SQL> conn / as sysdba Connected. SQL > create user yshy identified by yshy; User created. SQL > grant connect to yshy; Grant succeeded. SQL > grant resource to yshy; Grant succeeded. SQL > grant create synonym to yshy; Grant succeeded. SQL >
2:切换到yshy用户,并创建同义词针对scott.emp
SQL> conn yshy/ yshy Connected. SQL > create synonym y_emp for scott.emp; Synonym created.
3:查询同义词,提示表或视图不存在。
SQL> select * from y_emp; select * from y_emp * ERROR at line 1 : ORA - 00942 : table or view does not exist SQL >
4:登陆scott把emp表的查询权限授权给yshy用户。
SQL> conn scott/ tiger Connected. SQL > grant select on emp to yshy; Grant succeeded. SQL > conn yshy/ yshy; Connected. SQL > select * from y_emp;
【删除同义词】
DROP [PUBLIC] SYNONYM [schema.]sysnonym_name