Oracle 权限

--权限

--登陆用户查询自己权限(会话)
select * from session_privs;

--查询用户所拥有系统权限
SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE = 'USERNAME'; 

--查询用户所拥有对象权限
SELECT * FROM DBA_TAB_PRIVS WHERE GRANTEE = 'USERNAME';

--查询用户所拥有的角色
SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'USERNAME';


--具体细化
--系统权限
SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE = 'HEXT'
UNION ALL
SELECT * FROM DBA_SYS_PRIVS
WHERE GRANTEE IN (SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'HEXT');

--对象权限
SELECT * FROM DBA_TAB_PRIVS WHERE GRANTEE = 'HEXT'
UNION ALL
SELECT * FROM DBA_TAB_PRIVS
WHERE GRANTEE IN (SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'HEXT');

--查看所有用户
select * from dba_user;
select * from all_users;
select * from user_users;
--查看用户系统权限
select * from dba_sys_privs;
select * from all_sys_privs;
select * from user_sys_privs;
--查看用户对象权限
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
--查看所有角色
select * from dba_roles;
--查看用户所拥有的角色
select * from dba_role_privs;
select * from user_role_privs;

--查询一个角色包括的
--系统权限
select * from dba_sys_privs where grantee='角色名';
--对象权限
select * from dba_tab_privs where grantee='角色名';

--赋权
--比如用户A想操作用户B下的某一个表,那么可以登录用户B输入以下指令:
grant all on tablename to A;
--这样,A就拥有了B下面 tablename 这个表的所有权限。
--同理如果只是想赋某种权限的话,以下语句可供参考:
grant create tablespace to A;
grant select on tabelname to A;
grant update on tablename to A;
grant execute on procedurename to A; --授权存储过程
grant update on tablename to A with grant option; --授权更新权限给A用户,A用户也可以将此权限继续授权给别人;
--但是with grant option 这个命令有个权限管理问题,当管理员给A赋予上述权限时,则A可以把update tablename的权限赋予其他用户例如D,事后,如果管理员收回A的 with grant option 权限,则D的权限也失效,但管理员却不能直接从D那收回update tablename 的权限。

--授予其他用户表所有权限
grant all on lis.emp to mike;

--授予其他用户表增删改查权限
grant select,insert,delete,update on lis.emp to mike;

--增加awr权限
grant connect,select_catalog_role,ADVISOR to DZPRD;
grant execute on DBMS_WORKLOAD_REPOSITORY to DZPRD;

--查询数据库scn号的权限
GRANT EXECUTE ON DBMS_FLASHBACK TO SCOTT;
--or
--授予用户查询V$DATABASE视图的权限:
GRANT SELECT ON V_$DATABASE TO SCOTT;
--查询表根据scn号的权限
grant flashback on lis.REINSURERECORDTRACE to ODSQUERY;

--赋予用户查询表的权限
select 'grant select on '||owner||'.'||segment_name||' to datachg;' from dba_tables
where owner='LINSHI001';

--创建查看执行计划角色
create role plustrace;
--drop role plustrace;
grant select on v_$mystat to plustrace;
grant select on v_$session to plustrace;
grant select on v_$sesstat to plustrace;
grant select on v_$statname to plustrace;
grant select on v_$sql to plustrace;
grant select on v_$sql_plan to plustrace;
grant select on v_$sql_plan_statistics_all to plustrace;
--精简
grant select on v_$sesstat to plustrace;
grant select on v_$statname to plustrace;
grant select on v_$mystat to plustrace;


--权限检查SQL:
--指定某月的帐户查询
select t.username,
       t.account_status,
       t.lock_date,
       t.created,
       max(t1.granted_role) authority,
       'NO' 用户是否变化,
       ' ' 变化原因
  from DBA_USERS t, DBA_ROLE_PRIVS t1
 where t.username = t1.grantee
       and account_status='OPEN'
       and t.created>=date'2015-06-01'----根据提取月份修改
       and t.created<=date'2015-06-30'----根据提取月份修改
 group by t.username, t.account_status, t.lock_date,t.created  
union all
select t.username,
       t.account_status,
       t.lock_date,
       t.created,
       max(t1.granted_role) authority,
       'NO' 用户是否变化,
       ' ' 变化原因
  from DBA_USERS t, DBA_ROLE_PRIVS t1
 where t.username = t1.grantee
       AND account_status LIKE '%LOCK%'
       and  t.lock_date>=date'2015-06-01'----根据提取月份修改
       and t.lock_date<=date'2015-06-30'----根据提取月份修改
 group by t.username, t.account_status, t.lock_date,t.created
 order by account_status

--用户权限查询
--指定某月的帐户权限查询
SELECT T1.GRANTEE,
       T1.GRANTED_ROLE,
       t1.admin_option,
       'NO' 权限是否发生变化,
       '' 变化说明,
       t.created 变更日期
  FROM DBA_USERS T, DBA_ROLE_PRIVS T1
 WHERE T.USERNAME = T1.GRANTEE
   and account_status = 'OPEN'
   and t.created >= date '2015-06-01'  ----根据提取月份修改
   and t.created <= date '2015-06-30' ----根据提取月份修改
union
SELECT T1.GRANTEE,
       T1.GRANTED_ROLE,
       t1.admin_option,
       'NO' 权限是否发生变化,
       '' 变化说明,
       t.LOCK_DATE 变更日期
  FROM DBA_USERS T, DBA_ROLE_PRIVS T1
 WHERE T.USERNAME = T1.GRANTEE
   AND account_status LIKE '%LOCK%‘
   and t.lock_date >= date '2015-06-01'----根据提取月份修改
   and t.lock_date <= date '2015-06-30'----根据提取月份修改

-- 确定角色的权限
select * from role_tab_privs ;              包含了授予角色的对象权限
select * from role_role_privs ;             包含了授予另一角色的角色
select * from role_sys_privs ;              包含了授予角色的系统权限

-- 确定用户帐户所授予的权限
select * from DBA_tab_privs ;               直接授予用户帐户的对象权限
select * from DBA_role_privs ;              授予用户帐户的角色
select * from DBA_sys_privs ;               授予用户帐户的系统权限


--与权限有关的视图
ALL_TAB_PRIVS
ALL_TAB_PRIVS_MADE
ALL_TAB_PRIVS_RECD
DBA_SYS_PRIVS
DBA_ROLES
DBA_ROLE_PRIVS
ROLE_ROLE_PRIVS
ROLE_SYS_PRIVS
ROLE_TAB_PRIVS
SESSION_PRIVS
SESSION_ROLES
USER_SYS_PRIVS
USER_TAB_PRIV

你可能感兴趣的:(Oracle)