岗位表:s_position
pid   pname  state  parent
1     测试1    0      2/1
2     测试2    0     5/3/2
3      a       0       3
4      b       1
5      c       0
parent 说明: 用于岗位继承 如果值为本身id或空代表不继承,如果:例如5/3/2 代表继承了5,3的权限,parent 长度不固定问题: 如何查出所有的被继承的岗位id?

解决方案 »

  1.   

    select * from s_position t where instr('/'||
    (select parent from s_position  where pid=??)
    ||'/','/'|| t.pid||'/')>0
    ;
      

  2.   

    就是有个岗位表s_position 其中 parent 结构为 岗位id1/岗位id2.../岗位idn/本身岗位id
    岗位id1,..岗位idn 都是被继承的岗位id
    岗位是拥有权限的,我需要查到被继承的岗位的权限,就是得先拆分parent 字段的的数据获得所有被继承岗位id
      

  3.   

    select * from s_position a where instr('/'||
    (select parent from s_position b where b.pid=??)
    ||'/','/'|| a.pid||'/')>0 and a.pid<>b.pid;
      

  4.   

    上面sql写的有点问题,用这个吧
    SQL> select * from s_position;
     
    PID PNAME      STATE      PARENT
    --- ---------- ---------- --------------------
      1 测试1      0          2/1
      2 测试2      0          5/3/2
      3 a          0          3
      4 b          1          
      5 c          0          
     
    SQL> 
    SQL> SELECT *
      2    FROM S_POSITION A
      3   WHERE INSTR('/' || (SELECT SUBSTR(PARENT, 1, INSTR(PARENT, '/', -1, 1))
      4                         FROM S_POSITION B
      5                        WHERE B.PID = 2),
      6               '/' || A.PID || '/') > 0;
     
    PID PNAME      STATE      PARENT
    --- ---------- ---------- --------------------
      3 a          0          3
      5 c          0          
     
    SQL>