1.創(chuàng)建用戶
//<1> 以sysdba管理員登錄創(chuàng)建用戶smart/smart
sqlplus /nolog
conn /as sysdba;
create user smart identified by smart;
//<2> 查看所有的用戶列表(查看用戶是否創(chuàng)建成功)
select * from all_users;```
####2.授予權(quán)限
--為了能夠保證能夠登陸,必須賦予如下權(quán)限
--授予smart用戶創(chuàng)建session的權(quán)限,即登陸權(quán)限
grant create session to smart;
--授予smart用戶使用表空間的權(quán)限
grant unlimited tablespace to smart;
--授予smart用戶創(chuàng)建視圖的權(quán)限
grant create any view to smart;```
3.登錄另一用戶,為新建用戶smart授予訪問(wèn)指定表的權(quán)限
--oracle對(duì)權(quán)限管理比較嚴(yán)謹(jǐn),普通用戶之間也是默認(rèn)不能互相訪問(wèn)的,需要互相授權(quán).
--如果tianzhi_smart用戶要授權(quán)給smart用戶查看自己的zh_major_item表的權(quán)限;
sqlplus tianzhi_smart/tianzhi_smart@localhost:1521/orcl
--授予smart用戶查看指定的權(quán)限
grant select on zh_major_item to smart;```
####4.登錄新建用戶smart,創(chuàng)建視圖
// 登錄smart用戶
sqlplus smart/smart@localhost:1521/orcl
// 測(cè)試是否可以訪問(wèn)tianzhi_smart用戶下的zh_major_item表
select * from tianzhi_smart.zh_major_item;
// 創(chuàng)建視圖
create or replace force view vw_major_item
AS Select * from tianzhi_smart.zh_major_item
WITH READ ONLY;
// 測(cè)試視圖是否創(chuàng)建成功
//觀察是否與 select * from tianzhi_smart.zh_major_item;查詢結(jié)果相同
select * from vw_major_item;```