第1个回答 2013-04-18
declare
teacher_name varchar(20)------------跟teacher表中老师名字类型保持一致
cursor t_name is select teachername from teacher---------申明游标t_name为从teacher表中查询老师名字
begin
open t_name;------打开游标t_name
loop-------开始循环(遍历)
fetch t_name into teacher_name-------将老师名字值赋予变量teacher_name
if t_name%found-------------开始遍历有值时插入以下数据
then
select name,count(*) into new_table
from table_teacher_student
where name=teacher_name group by name-----将一个老师名字依据条件插入新表数据
else
dmbs_output.put_line(‘完成所有工作’);---------遍历结束时输出完成工作
exit;
end if;
end loop;
仓促写下以上内容,可能部分语法报错,思路就是这样,很基本的一个游标使用。本回答被提问者采纳