--给出一个部门号,计算该部门所有子部门的人员数
create or replace procedure p1 (deptno varchar2) is
begin
declare
i integer;
sum integer;
typenis varray(19) of number;
begin
selectcount(*) into sum_dept
from dept
where parent=dept_no;
while i<sum_dept loop
select count(*)
into n(i)
//问题2
from emp
wheredept_no=(select dept_no
先不管语法,如果有这段(rownum=i )就应该不能得出数据。
另外为何写得这么麻烦?
这样不就可以了吗:
select dept_no,count(*) from emp where dept_no in(select dept_no from dept where parent=deptno)
group by dept_no;
主要问题就是要把各子单位的人员数读到变量中,我就定义了个变量(数组型),但是值进不去: select count(*)
into array(i)
from *;
关于order by 的问题,我已经找到答案:嵌套表不支持order by
所以就想知道通过循环给动态数组写值可否
比如 :
while i<100 loop
select count(*)
into array(i)
where dept=i;