实际应用中,会遇到在某个用户下需要查询另一个用户下的表数据或视图的情况,然而在没有授权时,会提示无权限操作的错误。那就需要通过授权处理后,再能进行查询操作,下面我们来看看是怎么处理的。
一、系统权限说明:
1、用户权限
CREATE SESSIOIN 连接到数据库
CREATE TABLE 在用户的方案中创建表
CREATE SEQUENCE 在用户的方案中创建序列
CREATE VIEW 在用户的方案中创视图
CREATE PROCEDURE在用户的方案中创建存储过程,函数或包
1.1、例子:授予系统权限
DBA能够授予用户指定的系统权限
GRANT create session,create table,
create sequence,create view
TO scott;
二、创建用户只用于查询其它用户库的表和视图
1、创建用户
create user 用户名 identified by 密码; grant connect,select any table to 用户名; 这样创建的用户就可以连接数据库和只有对任何表有查询权限了
grant connect to 用户名 //只有连接权限 2、授权查询表与视图权限
2.1、a用户下授权查询所有表给b用户(a用户登录执行下面语句)
select 'grant select on a.' || tname || ' to b;' from tab; 'GRANTSELECTONA.'||TNAME||'TOB;'
grant select on a.VOTE_NUM to b; grant select on a.TMP_MSG to b; grant select on a.VOTE_IP to b; grant select on a.QUESTION to b; grant select on a.QUESTION_COUNT to b; grant select on a.RECORD_DICT to b; grant select on a.BM_COLUMN to b; grant select on a.BM_COLUMN_CLASSIFY_REL to b; grant select on a.BM_INFO_CLASSIFY to b; grant select on a.BM_MODULE to b; grant select on a.BM_MODULE_AUTH to b;
或
select 'grant select on '||table_name||' to b;' from user_tables;
'GRANTSELECTON'||TABLE_NAME||'TOB;'
grant select on VOTE_NUM to b; grant select on TMP_MSG to b; grant select on VOTE_IP to b; grant select on QUESTION to b; grant select on QUESTION_COUNT to b; grant select on RECORD_DICT to b; grant select on BM_COLUMN to b; grant select on BM_COLUMN_CLASSIFY_REL to b;
说明:在a用户下执行该语句,执行后会生成对所有表的赋权限语句,拷贝出来执行就可以了。
2.2、a用户下授权查询单个表给b用户
grant select on a.tablename to b;
2.3、a用户下授权查询所有序列给b用户
select 'grant select on ' || sequence_name || ' to b;' from dba_sequences where sequence_owner='A';
2.4、--Oracle查询用户视图
select * from user_views; 2.5、a用户下授权查询视图给test11用户
select 'grant select on a.' || view_name || ' to test11;' from user_views;
视图查询如下:
'GRANTSELECTON'||VIEW_NAME||'TOTEST11;'
grant select on CONFIRM_RESERVATION_VIEW to test11; grant select on DEPARTMENT_RESERVATION_VIEW to test11; grant select on DEPART_CANCEL_RESERVATION_VIEW to test11; grant select on DOCTOR_CANCEL_RESERVATION_VIEW to test11; grant select on DOCTOR_RESERVATION_VIEW to test11; grant select on GRPSS to test11; grant select on HOSPITAL_ALL_SCHEDULE_VIEW to test11; grant select on HOSPITAL_DEPARTMENT_VIEW to test11; grant select on HOSPITAL_DEP_SCHEDULE_VIEW to test11; grant select on HOSPITAL_DOCTOR_VIEW to test11; grant select on HOSPITAL_DOC_SCHEDULE_VIEW to test11;
'GRANTSELECTON'||VIEW_NAME||'TOTEST11;'
grant select on PATIENT_COUNT_RESERVATION_VIEW to test11; grant select on PATIENT_RESERVATION_VIEW to test11; grant select on PATIENT_RESERVATION_VIEW2 to test11; grant select on PATIENT_RES_VIEW to test11; grant select on PRVIEW to test11; grant select on RES_VIEW to test11; grant select on SS to test11; 备注:授权更新、删除的 语法和授权查询类似,只是关键字不同而已。
三、撤消权限
1、授权a用户下取消给b用户删除单个表的权限
revoke delete on a.tablename from b;
2、授权a用户下取消给b用户更新单个表的权限
revoke update on a.tablename from b;
3、拥有dba权限的用户下取消给b用户创建dblink的权限
revoke create database link from b;
4、拥有dba权限的用户下取消给tes11用户查询任何表的权限
revoke select any table from test11;
转载至:https://blog.csdn.net/weixin_33766805/article/details/92987893 如有侵权,请联系作者删除:renxuehang@foxmail.com
注意:本文归作者所有,未经作者允许,不得转载