请看这段代码

[复制链接]
查看11 | 回复2 | 2005-4-27 08:46:18 | 显示全部楼层 |阅读模式
--给出一个部门号,计算该部门所有子部门的人员数
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

from dept

where parent=dept_no and rownum=i

order by dept_no));//问题1

i:=i+1;
end loop;

end p1;

******************************************************************************
现在的问题是:1 出现pls-00103错误 (指向问题1行)

2 如果删除该行(问题1行),出现pls-00321错误
请大家帮忙看一下,问题到底出在哪里,该怎么写!
谢谢!
回复

使用道具 举报

千问 | 2005-4-27 08:46:18 | 显示全部楼层
先不管语法,如果有这段(rownum=i )就应该不能得出数据。
另外为何写得这么麻烦?
这样不就可以了吗:
select dept_no,count(*) from emp where dept_no in(select dept_no from dept where parent=deptno)
group by dept_no;
回复

使用道具 举报

千问 | 2005-4-27 08:46:18 | 显示全部楼层
主要问题就是要把各子单位的人员数读到变量中,我就定义了个变量(数组型),但是值进不去: select count(*)
into array(i)
from *;
关于order by 的问题,我已经找到答案:嵌套表不支持order by
所以就想知道通过循环给动态数组写值可否
比如 :
while i<100 loop
select count(*)
into array(i)
where dept=i;

end loop
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行