关系表:sys_function
id :主键id
pid:父关系id
Oracle函数:start with…connect by…prior
1.表数据
select * from family;
2.查询自己和自己所有的后代
select s.*
from family s
start with s.id = 'me'
connect by prior s.id = s.pid;
3.查询自己和自己的祖先
select s.*
from family s
start with s.id = 'me'
connect by s.id = prior s.pid;
4.查询自己所有的后代(不包括自己)
select s.*
from family s
start with s.pid = 'me'
connect by prior s.id = s.pid;
5.查询自己的第一代孩子和祖先(包括自己)
select s.*
from family s
start with s.pid = 'me'
connect by s.id = prior s.pid;