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