在實際生產中有這樣的需求:
業務用戶A有比較大的權限,外部訪問數據庫,如果通過A,安全隱患較多,所以需要創建一個用戶B,B只能查詢A擁有的表或視圖等對象,無法 insert/update/delete
1.創建用戶B
create user userB identified by "userB " default tablespace tbs1 temporary tablespace tbs1_temp profile DEFAULT;
2.授權
grant connect to userB; --連接權限
grant CREATE SESSION to userB; --創建會話權限
grant CREATE SYNONYM to userB; --創建同義詞權限
grant select any table to userB; --可以查詢任何表
--revoke SELECT ANY TABLE from userB; --回收權限
還有一種授權方式:授予某個用戶的某個表的 select/insert/update 權限
grant select on userA.t_bd_customer to userB;
grant insert on userA.t_bd_customer to userB;
grant update on userA.t_bd_customer to userB;
查看某個用戶擁有哪個表的哪些權限:
記住這個表:all_tab_privs
select * from all_tab_privs where GRANTEE='USERB';
3.創建同義詞,不創建就不能直接通過單獨的名詞來查詢
create synonym table1_sy for userA.table1;
附:批量創建同義詞的腳
select 'create or replace synonym '||object_name||' for '||owner||'.'||object_name||';' from dba_objects
where owner in ('USERA') and object_type='TABLE';
