登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Perfect-World

以無法為有法,以無限為有限!

 
 
 

日志

 
 

SQL栏目树的代码【转】  

2012-12-17 23:54:43|  分类: DBA |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

/**
  * Desc:
取栏目树 ,过滤用户权限和无效栏目
  * Author: WHL
  * Date: 2009-05-31 15:17
  */

 
/** 1.
取某用户有权限(np_cms_column_security表有记录且t.action_1 = '1′)的栏目的树 **/

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

create or replace view V_NP_CTREE_BS as

select B.* from (

select A.*, lag(A.column_id) over(partition by A.column_id order by 0 ) RK

  from (select /*+choose */

         t.*

          from np_cms_column t

         where t.is_active = '1'

        connect by prior t.column_id = t.parent_id

         start with t.column_id in (select t.column_id

                                from np_cms_column_security t

                               where t.subject_id = 'mazj'

                               /*这里添加角色过滤*/

                             and t.action_1 = '1'))A) B

 where not exists

 (select 0

          from (select distinct d.column_id

                  from np_cms_column d

                connect by prior d.column_id = d.parent_id

                 start with d.column_id in

                    (select t.column_id

                       from np_cms_column_security t

                      where t.subject_id = 'mazj'

                           /* 这里添加角色过滤*/

                        and t.action_1 = '0'

                           /* 排除有权限树下的非授权ID,既 Action_1=0的*/

                        and exists

                      (select 0

                               from (select distinct d.column_id

                                       from np_cms_column d

                                     connect by prior d.column_id =

                                                 d.parent_id

                                      start with d.column_id in

                                                 (select t.column_id

                                                    from np_cms_column_security t

                                                   where t.subject_id =

                                                         'mazj'

                                                        /*这里添加角色过滤*/

                                                     and t.action_1 = '1')) C1

                              where C1.column_id = t.column_id))

                        and d.is_active = '1') C

         where C.column_id = B.column_id and B.RK is null) and B.RK is null

union all

select c.*, 0 RK from np_cms_column c where c.parent_id = 0;

————————————————————————
/** 2.
得到栏目的虚拟父亲ID(考虑到把断层的节点接起来)**/

1

2

3

4

5

6

7

8

9

create or replace view V_NP_CTREE_PA as

select B.*,

       (case B.column_id

         when 1 then 0 else nvl(B.father, 1) end) VFA

  from (select v.*,

               (select vv.column_id

                  from V_NP_CTREE_BS vv

                 where vv.column_id = v.parent_id) FATHER

          from V_NP_CTREE_BS v) B;

————————————————————————
/** 3.
取出门户需要的栏目树 **/

1

2

3

4

5

6

7

8

9

--create or replace view V_NP_CTREE_RS as

select

 D.*, LPAD(' ', 2 * level - 1) || SYS_CONNECT_BY_PATH(D.COLUMN_NAME, '/') "Path"

  from (select c.*

          from V_NP_CTREE_PA c

         order by c.VFA, c.disorder desc, c.column_id desc) D

connect by prior D.column_id = D.VFA

 start with D.column_id = 1;

 

作者:whl

  评论这张
 
阅读(732)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018