ORACLE SQL 笔记

根据数据权限查询

 1 SELECT * FROM (
 2 SELECT ROWNUM AS ROWNO, AA.* FROM (
 3     SELECT DISTINCT A.OBJECTID InstanceID
 4         , A.PRIORITY Priority
 5         , INSTANCENAME InstanceName
 6         , A.WORKFLOWCODE WorkflowCode
 7         , C.WORKFLOWNAME WorkflowName
 8         , A.ORIGINATOR Originator
 9         , A.ORIGINATORNAME OriginatorName
10         , A.CREATEDTIME CreatedTime
11         , A.ORGUNIT
12         , D.DISPLAYNAME ApproverLink
13         , D.PARTICIPANTNAME Approver
14         , A.STATE InstanceState
15         , A.PLANFINISHTIME PlanFinishTime
16         , A.FINISHTIME FinishedTime
17         , A.EXCEPTIONAL Exceptional
18     FROM H3.OT_INSTANCECONTEXT A 
19         JOIN H3.OT_USER B ON A.ORIGINATOR = B.OBJECTID
20         JOIN H3.OT_WORKFLOWCLAUSE C ON A.WORKFLOWCODE = C.WORKFLOWCODE
21         LEFT JOIN  H3.OT_WORKITEM D ON A.OBJECTID = D.INSTANCEID
22     WHERE A.CREATEDTIME > to_date('2018-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
23     AND A.CREATEDTIME < to_date('2019-12-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
24     AND A.STATE = 2
25     AND A.WORKFLOWCODE IN ('ITService','test')
29     AND (B.CODE = 'xxx' 
30         OR (EXISTS
31                 (
32                     SELECT 1 FROM H3.OT_BIZOBJECTACL Z JOIN H3.OT_USER X ON Z.USERID=X.OBJECTID
33                     WHERE SCHEMACODE = A.WORKFLOWCODE AND (Z.ADMINISTRATOR=1 OR Z.CREATEBIZOBJECT=1 OR Z.VIEWDATA=1 ) 
34                         AND Z.ORGSCOPETYPE = 2 AND X.CODE = 'xxx' -- 模型权限 全组织
35                 )
36             OR EXISTS
37                 (
38                     -- 前端提交的 流程模板权限的组织范围
39                     SELECT  OBJECTID --, NAME
40                     FROM H3.OT_ORGANIZATIONUNIT
41                     WHERE A.ORGUNIT IN OBJECTID
42                     START WITH OBJECTID IN 
43                     (
44                         SELECT ORGSCOPE
45                         FROM H3.OT_BIZOBJECTACL Z JOIN H3.OT_USER X ON Z.USERID=X.OBJECTID
46                         WHERE SCHEMACODE = A.WORKFLOWCODE AND (Z.ADMINISTRATOR=1 OR Z.CREATEBIZOBJECT=1 OR Z.VIEWDATA=1 ) 
47                             AND Z.ORGSCOPETYPE = 0 AND X.CODE = 'xxx' -- 模型权限 特定范围
48                     )
49                     CONNECT BY PRIOR OBJECTID = PARENTID 
50                  )
51             )
52         )
53     AND (A.ORIGINATOR = 'b11b0075-cd3f-4953-a3e4-331671f87ca7' -- 前端组织范围选择具体的人
54             OR A.ORGUNIT IN
55             (
56                 -- 前端提交的 只查看此组织范围
57                 SELECT  OBJECTID --, NAME
58                 FROM H3.OT_ORGANIZATIONUNIT
59                 START WITH OBJECTID IN ( '5b95c20d-ad64-453f-badd-4d12c8327ead' )
60                 CONNECT BY PRIOR OBJECTID = PARENTID 
61             )
62         )
63     ORDER BY A.CREATEDTIME DESC
64 ) AA 
65 WHERE ROWNUM <= 10
66 ) BB 
67 WHERE ROWNO >= 1

 

你可能感兴趣的:(ORACLE SQL 笔记)