Oracle 存储过程
存储过程:
declare cursor cu_student(minAge in number,maxAge in number) is
select * from students
where student_age>=minAge and student_age<=maxAge;
student students%rowtype;
begin
open cu_student(19,20);
fetch cu_student into student;
while cu_student%found loop
dbms_output.put_line(student.student_name||':'||
student.student_age||'岁');
fetch cu_student into student;
end loop;
close cu_student;
end;
请问如下语句在如上存储过程中是什么意义?由其是while cu_student%found loop这句是什么意思?
-while cu_student%found loop
-dbms_output.put_line(student.student_name||':'||
-student.student_age||'岁');
-fetch cu_student into student;
-end loop;
------解决方案--------------------我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html
------解决方案-------------------- %FOUND %NOTFOUND 判断游标所在的行是否有效,如果有效,则%FOUNDD等于true,否则等于false
------解决方案--------------------SQL code
declare
--定义一个参数游标,参数为minAge,maxAge
cursor cu_student(minAge in number, maxAge in number) is
select *
from students
where student_age >= minAge
and student_age <= maxAge;
--定义一个students类型的变量
student students%rowtype;
begin
open cu_student(19, 20); --打开游标,用19,20作参数
fetch cu_student --取出一条记录到student变量中
into student;
while cu_student%found loop --当发现有取出记录时,循环游标,没有取得记录时就会退出
dbms_output.put_line(student.student_name || ':' || --打印当前取出的这记录信息
student.student_age || '岁');
fetch cu_student --从游标中取出一条记录到student变量中
into student;
end loop;
close cu_student; --游标需要关闭
end;