Oracle資料庫新建使用者併為其建立一個檢視(示例)
阿新 • • 發佈:2019-01-10
1.建立使用者
//<1> 以sysdba管理員登入建立使用者smart/smart
sqlplus /nolog
conn /as sysdba;
create user smart identified by smart;
//<2> 檢視所有的使用者列表(檢視使用者是否建立成功)
select * from all_users;
2.授予許可權
--為了能夠保證能夠登陸,必須賦予如下許可權
--授予smart使用者建立session的許可權,即登陸許可權
grant create session to smart;
--授予smart使用者使用表空間的許可權
grant unlimited tablespace to smart;
--授予smart使用者建立檢視的許可權
grant create any view to smart;
3.登入另一使用者,為新建使用者smart授予訪問指定表的許可權
--oracle對許可權管理比較嚴謹,普通使用者之間也是預設不能互相訪問的,需要互相授權.
--如果tianzhi_smart使用者要授權給smart使用者檢視自己的zh_major_item表的許可權;
sqlplus tianzhi_smart/[email protected]:1521/orcl
--授予smart使用者檢視指定的許可權
grant select on zh_major_item to smart;
4.登入新建使用者smart,建立檢視
//登入smart使用者
sqlplus smart/[email protected]:1521/orcl
//測試是否可以訪問tianzhi_smart使用者下的zh_major_item表
select * from tianzhi_smart.zh_major_item;
//建立檢視
create or replace force view vw_major_item
AS Select * from tianzhi_smart.zh_major_item
WITH READ ONLY;
//測試檢視是否建立成功
//觀察是否與 select * from tianzhi_smart.zh_major_item;查詢結果相同
select * from vw_major_item;