存储过程中使用临时表
小林寒风 2010-09-03 11:20:21 现有一学生表STUDENT,包含三个字段,分别为学号sno(数值)、姓名sname(字符串)、成绩score(数值 两位小数),其中学号为主键,要求:写一个存储过程,输入四个参数,第一个,类型,第二个,学号,第三个,姓名,第四个,成绩。(输入类型包括Q查询,U修改,D删除)
输入Q,查询输入的第一个学号的信息
输入U,根据学号修改学生的姓名和程序,姓名和成绩为第二个第三个参数.并将修改后的信息查询出来
输入D,删除输入学号的学生信息。并显示要删除的学生的信息.用临时表.
create or replace procedure pro_student (typ char,stuno number,stuname varchar2,stuscore number) as
v_stuno number;
v_stuname varchar2(50);
v_stuscore number;
begin
case lower(typ)
when 'q' then
select sno into v_stuno from student where sno=stuno;
select sname into v_stuname from student where sno=stuno;
select score into v_stuscore from student where sno=stuno;
dbms_output.put_line(to_char(v_stuno)||' '||v_stuname||' '||to_char(v_stuscore));
when 'u' then
update student set sname=stuname,score=stuscore
where sno=stuno;
commit;
when 'd' then
execute immediate
'create global temporary table student_temp as select * from student
where sno=stuno on commit delete rows';
delete from student where sno=stuno;
--select * from student_temp;
end case;
end;
查询和修改都没问题。
用临时表时,提示未正确结束,求高手指点下怎么写