17,086
社区成员
发帖
与我相关
我的任务
分享
SQL>
SQL> select tab.人员编号, tab.人员姓名, t.right_name 已授权限
2 from (select distinct rri_right_id 已授权限,
3 -- rri_role_id,
4 c.staff_name 人员姓名,
5 c.staff_no 人员编号
6 from role_right_info a, role_staff_or_dept_info b, staff_info c
7 where a.rri_role_id = b.rsd_role_id
8 and rsd_is_staff_or_dept = 'S'
9 and c.staff_id = b.rsd_staff_or_dept_id
10 union
11 select distinct rri_right_id 已授权限,
12 -- rri_role_id,
13 c.staff_name 人员姓名,
14 c.staff_no 人员编号
15 from role_right_info a,
16 role_staff_or_dept_info b,
17 staff_info c,
18 dept_info d
19 where a.rri_role_id = b.rsd_role_id
20 and rsd_is_staff_or_dept = 'D'
21 and c.staff_dept_id = d.dept_id
22 and d.dept_id = b.rsd_staff_or_dept_id) tab,
23 right_info t
24 where tab.已授权限 = t.right_id
25 order by tab.人员编号;
人员编号 人员姓名 已授权限
-------- ---------- ----------------
S000001 张三 A模块新增
S000001 张三 A模块修改
S000001 张三 A模块删除
S000001 张三 B模块新增
S000001 张三 B模块删除
S000001 张三 B模块修改
S000002 李四 A模块新增
S000002 李四 A模块修改
S000002 李四 A模块删除
S000003 王五 B模块新增
S000003 王五 B模块删除
S000003 王五 B模块修改
S000006 赵六2 A模块新增
S000006 赵六2 A模块删除
S000006 赵六2 A模块修改
15 rows selected
SQL>
STAFF_ID STAFF_NO STAFF_NAME STAFF_DEPT_ID
1 S000001 张三 2
2 S000002 李四 3
3 S000003 王五 4
4 S000004 赵六 5
5 S000005 赵六1 7
6 S000006 赵六2 3
7 S000007 赵六3 6
8 S000008 赵六4 8
DEPT_ID DEPT_NO DEPT_NAME DEPT_PARENT_ID
1 D000001 总公司 0
2 D000002 A公司 1
3 D000003 B公司 1
4 D000004 A部门1 2
5 D000005 A部门2 2
6 D000006 B部门1 3
7 D000007 B部门2 3
8 D000008 C部门1 4
RIGHT_ID RIGHT_NAME RIGHT_PARENT_ID
1 A模块 0
2 A模块新增 1
3 A模块修改 1
4 A模块删除 1
5 B模块 0
6 B模块新增 5
7 B模块修改 5
8 B模块删除 5
ROLE_ID ROLE_NAME
1 系统管理员
2 A模块维护人员
3 A模块录入人员
4 B模块维护人员
5 B模块录入人员
RRI_ID RRI_ROLE_ID RRI_RIGHT_ID
1 1 2
2 1 3
3 1 4
4 1 6
5 1 7
6 1 8
7 2 2
8 2 3
9 2 4
10 4 6
12 4 7
13 4 8
RSD_ID RSD_ROLE_ID RSD_STAFF_OR_DEPT_ID RSD_IS_STAFF_OR_DEPT
1 1 1 S
2 2 2 S
3 2 3 D
4 4 4 D
-- (不理解你部门上下级关系是什么,是为权限的向上累加??)
-- 下面是没有上下级部门关系的写法:
SQL> SELECT f.STAFF_NO "人员编号",f.STAFF_NAME "人员姓名",c.RIGHT_NAME "已授权限"
2 FROM ROLE_RIGHT_INFO a,ROLE_INFO b, RIGHT_INFO c,
3 DEPT_INFO d,ROLE_STAFF_OR_DEPT_INFO e,STAFF_INFO f
4 WHERE b.ROLE_ID = a.RRI_ROLE_ID(+)
5 AND a.RRI_RIGHT_ID = c.RIGHT_ID(+)
6 AND d.DEPT_ID = e.RSD_STAFF_OR_DEPT_ID(+)
7 AND e.RSD_IS_STAFF_OR_DEPT(+) = 'D'
8 AND e.RSD_STAFF_OR_DEPT_ID = b.ROLE_ID(+)
9 AND f.STAFF_DEPT_ID = d.DEPT_ID(+)
10 ORDER BY f.STAFF_ID
11 /
人员编号 人员姓名 已授权限
-------------------- -------------------- --------------------
S000001 张三 B模块新增
S000001 张三 B模块修改
S000001 张三 B模块删除
S000002 李四
S000003 王五
S000004 赵六
S000005 赵六1
S000006 赵六2
S000007 赵六3
S000008 赵六4
10 rows selected
SQL>
-- 查出A公司所有的一级部门ID:
select dept_id from dept_no
start with dept_name = 'A公司'
connect by prior dept_id = dept_parent_id order by dept_id