pl / sql查询以通过deptno
查找经理名称DECLARE
V_ENAME EMP.ENAME%TYPE;
BEGIN
FOR I IN (SELECT distinct DEPTNO FROM EMP)
LOOP
SELECT ENAME INTO V_ENAME FROM EMP
WHERE JOB='MANAGER' AND DEPTNO=I.DEPTNO;
DBMS_OUTPUT.PUT_LINE('THE NAME OF THE MANAGER IN '||I.DEPTNO||' IS '||V_ENAME);
END LOOP;
END;
答案 0 :(得分:0)
工作正常
DECLARE
V_ENAME EMP.ENAME%TYPE;
BEGIN
FOR I IN (SELECT distinct DEPTNO FROM EMP)
LOOP
SELECT ENAME INTO V_ENAME FROM EMP
WHERE JOB='MANAGER' AND DEPTNO=I.DEPTNO;
DBMS_OUTPUT.PUT_LINE('THE NAME OF THE MANAGER IN DEPARTMENT '||I.DEPTNO||' IS '||V_ENAME);
END LOOP;
END;
打印
THE NAME OF THE MANAGER IN DEPARTMENT 30 IS BLAKE
THE NAME OF THE MANAGER IN DEPARTMENT 20 IS JONES
THE NAME OF THE MANAGER IN DEPARTMENT 10 IS CLARK
答案 1 :(得分:0)
由于我不知道这个线程的重点是什么,我将提供简单的SQL查询来执行问题中的问题 - 获取部门的deptno和管理器的名称(使用标量子查询)。
select d.deptno,
(select e.ename
from emp e
where e.deptno = d.deptno
and e.job = 'MANAGER') manager
from dept d;
这里没有理由使用PL / SQL。