如何?Oracle中使用者B只能訪問使用者A的視圖

來源:互聯網
上載者:User

我們有這樣一個需求:在資料庫中建立兩個使用者,使用者A 用於建立一些視圖,直接存取自己資料庫中一個模式下的表,以及通過資料庫鏈路訪問其他資料庫中的表;另一個使用者B 能訪問到這個使用者A 中的視圖,並且只能訪問視圖,且訪問串連數有限制。

這個使用者B 是用來給其他系統訪問的,因此對許可權和資源使用都需要有限制條件。

這種需求在很多行業的應用中都很常見。假如這是一道面試題,您該如何去回答呢?

我採用下面的方法來回答這個問題。

第一步,建立新使用者A 和B 。

這裡使用者名稱稱分別為ryd_interface_src  和ryd_interface ,對這兩個使用者都授予非常有限的許可權。

drop user ryd_interface_src cascade;

create user ryd_interface_src identified by ryd_interface_src;

grant connect,create view to ryd_interface_src;

 

drop user ryd_interface cascade;

create user ryd_interface identified by ryd_interface;

grant connect,create synonym to ryd_interface;

第二步,登入資料庫一個模式中,授權給使用者A ,使得使用者A 能建立視圖

conn qlzqclient/qlzqclient

grant select on INVEST_CLOCK  to ryd_interface_src with grant option;

grant select on INVEST_LOG   to ryd_interface_src with grant option;

這裡授權方法加了一個with grant option ,請注意。

第三步,登入資料庫使用者A 中,建立視圖

conn ryd_interface_src/ryd_interface_src

create or replace view run_views as

select id as doc_id, title,fbsj as upload_date,'' as branch_code from qlzq.runs_lantern@CLIENT_QLZQWEB

where EXT1='1' and sysdate >  START_TIME

and sysdate < SOLID_TIME

union

select a.doc_id,a.title,a.upload_date,a.branch_code  from qlzq.cms_doc_single_attr@CLIENT_QLZQWEB a

left   join qlzq.cms_doc_category_map@CLIENT_QLZQWEB b on a.doc_id=b.doc_id

where

a.state =1 and a.is_delete =0

and  a.upload_date> sysdate-90

and  b.cat_id=4;

 

create or replace view INVEST_CLOCK_VIEWS as

select  *  from  qlzqclient.INVEST_CLOCK;

 

create or replace view INVEST_LOG_VIEWS as

select  *  from  qlzqclient.INVEST_LOG;

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.