SQL实例代码:取栏目树,过滤用户权限和无效栏目
http://www.itjxue.com 2015-07-17 09:23 来源:未知 点击次数:
文由网友whl供稿,特此感谢!
/**
* Desc: 取栏目树 ,过滤用户权限和无效栏目
* Author: WHL
* Date: 2009-05-31 15:17
*/
/** 1. 取某用户有权限(np_cms_column_security表有记录且t.action_1 = ‘1′)的栏目的树 **/ 01.createorreplaceviewV_NP_CTREE_BSas 02.selectB.*from( 03.selectA.*, lag(A.column_id) over(partitionbyA.column_idorderby0 ) RK 04. from(select/*+choose */ 05. t.* 06. fromnp_cms_column t 07. wheret.is_active ='1' 08. connectbypriort.column_id = t.parent_id 09. startwitht.column_idin(selectt.column_id 10. fromnp_cms_column_security t 11. wheret.subject_id ='mazj' 12. /*这里添加角色过滤*/ 13. andt.action_1 ='1'))A) B 14. wherenotexists 15. (select0 16. from(selectdistinctd.column_id 17. fromnp_cms_column d 18. connectbypriord.column_id = d.parent_id 19. startwithd.column_idin 20. (selectt.column_id 21. fromnp_cms_column_security t 22. wheret.subject_id ='mazj' 23. /* 这里添加角色过滤*/ 24. andt.action_1 ='0' 25. /* 排除有权限树下的非授权ID,既 Action_1=0的*/ 26. andexists 27. (select0 28. from(selectdistinctd.column_id 29. fromnp_cms_column d 30. connectbypriord.column_id = 31. d.parent_id 32. startwithd.column_idin 33. (selectt.column_id 34. fromnp_cms_column_security t 35. wheret.subject_id = 36. 'mazj' 37. /*这里添加角色过滤*/ 38. andt.action_1 ='1')) C1 39. whereC1.column_id = t.column_id)) 40. andd.is_active ='1') C 41. whereC.column_id = B.column_idandB.RKisnull)andB.RKisnull 42.unionall 43.selectc.*, 0 RKfromnp_cms_column cwherec.parent_id = 0;
————————————————————————
/** 2.得到栏目的虚拟父亲ID(考虑到把断层的节点接起来)**/
————————————————————————
/** 3. 取出门户需要的栏目树 **/