1 select level,empno,ename,sal,mgr 2 from emp 3 connect by prior empno=mgr 4 start with mg



SQL> select count(*)
2 from emp e,emp b
3 ;


COUNT(*)
----------
196


SQL> select e.ename||'的老板是'||b.ename
2 from emp e,emp b
3 where e.mgr=b.empno;


E.ENAME||'的老板是'||B.ENAME
----------------------------
FORD的老板是JONES
SCOTT的老板是JONES
TURNER的老板是BLAKE
ALLEN的老板是BLAKE
WARD的老板是BLAKE
JAMES的老板是BLAKE
MARTIN的老板是BLAKE
MILLER的老板是CLARK
ADAMS的老板是SCOTT
BLAKE的老板是KING
JONES的老板是KING


E.ENAME||'的老板是'||B.ENAME
----------------------------
CLARK的老板是KING
SMITH的老板是FORD


已选择13行。


SQL> select lever,empno,ename,sal,mgr
2 from emp
3 connect by prior,empno=mgr
4 start with mgr id null
5 order by 1;
connect by prior,empno=mgr
*
第 3 行出现错误:
ORA-00936: 缺失表达式




SQL> ed
已写入 file afiedt.buf


1 select lever,empno,ename,sal,mgr
2 from emp
3 connect by prior empno=mgr
4 start with mgr id null
5* order by 1
SQL> /
start with mgr id null
*
第 4 行出现错误:
ORA-00920: 无效的关系运算符




SQL> ed
已写入 file afiedt.buf


1 select lever,empno,ename,sal,mgr
2 from emp
3 connect by prior empno=mgr
4 start with mgr is null
5* order by 1
SQL> /
select lever,empno,ename,sal,mgr
*
第 1 行出现错误:
ORA-00904: "LEVER": 标识符无效




SQL> ed
已写入 file afiedt.buf


1 select level,empno,ename,sal,mgr
2 from emp
3 connect by prior empno=mgr
4 start with mgr is null
5* order by 1
SQL> /


LEVEL EMPNO ENAME SAL MGR
---------- ---------- ---------- ---------- ----------
1 7839 KING 5000
2 7566 JONES 2975 7839
2 7698 BLAKE 2850 7839
2 7782 CLARK 2450 7839
3 7902 FORD 3000 7566
3 7521 WARD 1250 7698
3 7900 JAMES 950 7698
3 7934 MILLER 1300 7782
3 7499 ALLEN 1600 7698
3 7788 SCOTT 3000 7566
3 7654 MARTIN 1250 7698


LEVEL EMPNO ENAME SAL MGR
---------- ---------- ---------- ---------- ----------
3 7844 TURNER 1500 7698
4 7876 ADAMS 1100 7788
4 7369 SMITH 800 7902


已选择14行。


SQL>

你可能感兴趣的:(Connect by)