Oracle數(shù)據(jù)庫(kù)新建用戶并為其創(chuàng)建一個(gè)視圖(示例)

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;```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容