Oracle授權A使用者查詢B使用者的所有表
Oracle授權A使用者查詢B使用者的所有表
需求:
新建的使用者userA,要授權給他訪問使用者scott的所有表
有三種兩方法:
1)
SQL> conn / as sysdba;
SQL> grant select any table on userA
這種方法的缺點是授予的許可權過大,userA不僅可以訪問scott下的所有表,也可以訪問其他使用者包括sys,system下的所有表。
2)
SQL> conn scott/tiger;
SQL> select 'GRANT SELECT ON' || table_name || 'to userA;' from user_tables
得到的結果如下
grant select on emp to userA;
grant select on dept to userA;
grant select on bonus to userA;
grant select on loc to userA;
再把上面得到的結果逐一執行一遍:
SQL> grant select on emp to userA;
SQL> grant select on dept to userA;
SQL> grant select on bonus to userA;
SQL> grant select on loc to userA;
這種方法的缺點是要執行比較多的語句,如果有100個表,就得執行100個grant語句;
另外scott新建的表不在被授權的範圍內,新建的表要想被userA訪問,也得執行grant語句:
grant select on 新建的表 to userA;
(3)使用遊標
先建立兩個使用者
SQL> create user test1 identified by oracle;
User created.
SQL> create user test2 identified by oracle;
User created.
授權
SQL> grant connect, resource to test1;
Grant succeeded.
SQL> grant connect, resource to test2;
Grant succeeded.
在test2下建立一個表作測試用
SQL> conn test2/oracle;
Connected.
SQL> create table t(id number);
Table created.
建立角色並用遊標給角色授權
SQL> conn /as sysdba;
Connected.
SQL> create role select_all_test2_tab;
Role created
SQL>
declare
CURSOR c_tabname is select table_name from dba_tables where owner = 'TEST2';
v_tabname dba_tables.table_name%TYPE;
sqlstr VARCHAR2(200);
begin
open c_tabname;
loop
fetch c_tabname into v_tabname;
exit when c_tabname%NOTFOUND;
sqlstr := 'grant select on test2.' || v_tabname ||' to select_all_test2_tab';
execute immediate sqlstr;
end loop;
close c_tabname;
end;
/
PL/SQL procedure successfully completed.
把角色授權給test1
SQL> grant select_all_test2_tab to test1;
Grant succeeded.
嘗試用test1訪問test2的表
SQL> conn test1/oracle;
Connected.
SQL> select * from test2.t;
no rows selected
在test2下新建表
SQL> conn test2/oracle;
Connected.
SQL> create table ta(id number);
Table created.
嘗試用test1訪問新建的表
SQL> conn test1/oracle;
Connected.
SQL> select * from test2.ta;
select * from test2.ta
*
ERROR at line 1:
ORA-00942: table or view does not exist
結論:與第二種方案相比,用這種方式不需逐一把test2下的表授權給test1訪問,但test2新建的表無法被test1訪問。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29485627/viewspace-1252563/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle建立使用者、角色、授權、建表Oracle
- oracle新建使用者,表空間,並授權Oracle
- Oracle新建表空間、使用者及授權Oracle
- Oracle建立使用者和授權Oracle
- MongoDB建立只讀使用者並授權指定集合的查詢許可權MongoDB
- UserService 查詢使用者查詢許可權 isGlobalQuery分析
- MySql查詢使用者許可權MySql
- 使用者授權,策略的使用
- Oracle 刪除使用者、表空間、資料檔案、使用者下的所有表Oracle
- 查詢資料庫中的所有的普通使用者資料庫
- MySQL新增使用者使用者與授權MySql
- linux 新建使用者授權Linux
- 查詢資料庫授權以及授權到期的處理方法資料庫
- 授權|取消授權MYSQL資料庫使用者許可權MySql資料庫
- MySQL建立使用者和授權MySql
- mysql使用者建立與授權MySql
- Shiro實現使用者授權
- 查詢表中所有列名
- Oracle統計某個使用者下所有表的各自行數Oracle
- vertica建立新使用者並授權
- 使用者建立授權及刪除
- Mysql 建立資料庫\新增使用者\使用者授權MySql資料庫
- 微信授權獲取使用者的openid
- UserService 修改使用者查詢許可權 changeGlobalQuery分析
- UserService 刪除使用者查詢許可權 deleteUserPermission分析delete
- 如何查詢Linux系統中密碼為空的所有使用者Linux密碼
- oracle 例項表查詢Oracle
- oracle表複雜查詢Oracle
- oracle表查詢的並行度Oracle並行
- UserService 查詢使用者有許可權的關聯索引 queryIndexPatternByUserName分析索引Index
- 為何SYSTEM使用者可以將V$SESSION的查詢許可權賦權給其他使用者而SYS使用者卻不可以?Session
- SQL學習之子查詢,基於Oracle下的HR使用者(四)SQLOracle
- MySQL-授權使用者管理資料庫MySql資料庫
- 【ASP.NET Core】按使用者角色授權ASP.NET
- UserService 查詢使用者沒許可權的索引,增加臨時許可權queryIndicesNoPermission分析索引
- Oracle新建使用者、表空間、表Oracle
- Oracle12C查詢自建使用者(非系統自帶)Oracle
- Oracle使用者角色許可權管理Oracle
- oracle11g 查詢臨時表空間的使用率和正在使用臨時表空間的使用者Oracle