用SQL语句查询当前用户的所有权限
工具/材料:Management Studio。
1、首先在桌面上,点击“Management Studio”图标。
2、继续在该界面中,点击左上角“新建查询”选项。
3、其次在该界面中,输入查询当前用户的所有权限的sql语句“select * from myRole left join myUser on UserNo = '1' and myUser.RoleNo = myRole.RoleNo”。
4、然后在该界面中,点击左上方“执行”按钮。
5、最后在该界面中,显示查询当前用户的所有权限成功。
1、创建测试表,
create table test_user(user_id number, role_id number);
create table test_role(role_id number, role_name varchar2(20), right_id number);
create table test_right(right_id number, right_name varchar2(20));
2、插入测试数据
insert into test_user values(1,1001);
insert into test_user values(2,1001);
insert into test_user values(3,1002);
insert into test_user values(4,1002);
insert into test_role values(1001,'管理员',2001);
insert into test_role values(1001,'管理员',2002);
insert into test_role values(1002,'普通人员',2001);
insert into test_right values(2001,'查看');
insert into test_right values(2002,'修改');
3、查询三张表的总记录数,
select 'USER' v, count(*)
from test_user t
union all
select 'ROLE' v, count(*)
from test_role t
union all
select 'RIGHT' v, count(*)
from test_right t
4、编写sql,查询用户的角色、权限id、权限名称,
select t.user_id, t.role_id, b.right_id, c.right_name
from test_user t, test_role b, test_right c
where t.role_id = b.role_id
and b.right_id = c.right_id,
下面内容供你参考
1.查看所有用户:
select * from dba_users;
select * from all_users;
select * from user_users;
2.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
select * from dba_sys_privs;
select * from user_sys_privs;
3.查看角色(只能查看登陆用户拥有的角色)所包含的权限
sql>select * from role_sys_privs;
4.查看用户对象权限:
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
5.查看所有角色:
select * from dba_roles;
6.查看用户或角色所拥有的角色:
select * from dba_role_privs;
select * from user_role_privs;
7.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
select * from V$PWFILE_USERS
比如我要查看用户 wzsb的拥有的权限:
SQL> select * from dba_sys_privs where grantee='WZSB';
GRANTEE PRIVILEGE ADMIN_OPTION
------------------------------ ---------------------------------------- ------------
WZSB CREATE TRIGGER NO
WZSB UNLIMITED TABLESPACE NO
比如我要查看用户 wzsb的拥有的角色:
SQL> select * from dba_role_privs where grantee='WZSB';
GRANTEE GRANTED_ROLE ADMIN_OPTION DEFAULT_ROLE
------------------------------ ------------------------------ ------------ ------------
WZSB DBA NO YES
查看一个用户所有的权限及角色
select privilege from dba_sys_privs where grantee='WZSB'
union
select privilege from dba_sys_privs where grantee in
(select granted_role from dba_role_privs where grantee='WZSB' );