存储过程中使用临时表
现有一学生表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;
查询和修改都没问题。
用临时表时,提示未正确结束,求高手指点下怎么写
输入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;
查询和修改都没问题。
用临时表时,提示未正确结束,求高手指点下怎么写
...全文
相关推荐
Oracle存储过程中使用临时表
Oracle存储过程中使用临时表 会话级临时表 事务级临时表
存储过程中的临时表使用方法
创建临时表。临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。
存储过程:利用游标+临时表实现查询
存储过程使用游标、临时表实现动态SQL查询 2020.3.24 用能第二周周二上午,任务需求:编写存储过程查询监测设备状态以及目标监测设备状态。(任务完成) 改存储过程包含了大量相关知识,特此记录,以便此后使用! 为什么要是用存储过程? 1.存储过程只在创造时进行编译,以后每次执行存储过程都不需再重新编译,而一般SQL语句每执行一次就编译一次,所以使用存储过程可提高数据库执行速度。 2.当对数据库进行复杂操作时(如对多个表进行Update,Insert,Query,Delete时),可以将复杂操作用存储过程封装起来与数据库提供的事务处理结合一起使用。 3.存储过程可以重复使用,可减少数据库开发
MySQL 存储过程与游标的混合使用
MySQL 存储过程与游标的混合使用,也没啥重要的,就是和其他数据库有一些不同而已,作为总结,以后复习
存储过程,要用到指针,临时表
存储过程,要用到指针,临时表 存储过程,要用到指针,临时表 存储过程,要用到指针,临时表 存储过程,要用到指针,临时表



