Oracle中使用同義詞的方法介紹

來源:果殼範文吧 2.74W

  一、背景

Oracle中使用同義詞的方法介紹

有兩個sid:Asid,Bsid,在Asid下有兩個使用者Auser1,Auser2,在Bsid下有一個使用者Buser1。其中Auser2和Buser1建立了dblink。現希望通過登入Buser1訪問Auser1上的三張表table1,table2,table3資訊和函式function1。

 二、步驟

 ①登入Auser1對Auser2授權(若需要刪除則加上)

grant ,select,u

pdate on table1 to Auser2;

grant ,select,on table2 to Auser2;

grant ,select,on table3 to Auser2;

grant execute on function1 to Auser2;

 ②登入Auser2建立同義詞

create synonym table1 for e1;

create synonym table2 for e1;

create synonym table3 for e1;

create synonym function1 for tion1;

 ③登入Buser1查詢db_link名(例如查出來的db_link名為mydblink1)

select username,db_link from user_db_links

  ④建立Buser1的.同義詞

create synonym table1 for e1@mydblink1;

create synonym table2 for e2@mydblink1;

create synonym table3 for e3@mydblink1;

create synonym function1 for tion1@mydblink1;

  ⑤測試

此時登入Buser1通過select * from table1就可以訪問table1了。

  三、注意點

也可以建立procedure的同義詞,但是這樣執行的過程中不允許commit。如果要提交的話請在如JDBC中commit()。

熱門標籤