在行: 2 上开始执行命令时出错 -
DECLARE
--系的光标
cursor cdept is select dno,dname from dep;
pdno dep.dno%type;
pdname dep.dname%type;
--成绩光标
cursor cgrade(coursename varchar2,depno number) is select grade from sc where cno=(select cno from course where cname=coursename)
and sno in (select sno from student where dno=depno);
pgrade sc.grade%type;
count1 number;
count2 number;
count3 number;
avggrade number;
pcourseName varchar2 := '大学物理';
begin
open cdept;
loop
--取一个系的信息
fetch cdept into pdno,pdname;
exit when cdept %notfound;
--初始化工作
count1:=0;count2:=0;count3:=0;
--系的平均成绩
select avg(grade) into avggrade from sc where cno=(select cno from course where cname=pcoursename)
and sno in (select sno from student where dno=pdno);
--取系中,选修了大学物理的学生成绩
open cgrade(pcoursename,pdno);
loop
fetch cgrade into pgrade;
exit when cgrade%notfound;
if pgrade < 60 then count1:=count1+1;
elsif pgrade >=60 and pgrade <85 then count2:=count2+1;
else count3:=count3+1;
end if;
end loop;
close cgrade;
insert into msg1 values ( pcoursename,pdname,count1,count2,count3,avggrade);
end loop;
close cdept;
COMMIT;
dbms_output.put_line('统计完成');
end ;
错误报告 -
ORA-06550: 第 16 行, 第 19 列:
PLS-00215: 字符串长度限制在范围 (1...32767)
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
pcoursename 需要指定长度~~
varchar2,如果在pl/sql中它是以输入或输出参数的长度为准,如果在SQL中(比如创建表时)它是不允许不指定长度的. 所以 老师在视频中没有设定长度编译也可以通过
cursor cgrade(coursename varchar2,depno number)
为什么 这个varchar2 可以不指定长度 ,不太明白 求解答