层次查询

  • PRIOR :之前的
  • 从员工7876出发向上查看
select empno, ename, job, mgr
from emp 
start with empno = 7876
connect by prior mgr = empno
  • 从员工KING出发向下查看
select level, ename ||'work for' ||prior ename
from emp 
start with ename='KING'
connect by prior empno = mgr
order by level
  • lpad(列名,总长度,列名对应的值不足总长度的话,左边补充的字符)
  • where ename<>'JONES' 不显示JONES
  • connect by中加入ename<>'JONES'意思是不显示JONES之后的所有人

你可能感兴趣的:(层次查询)