题目:编写一个存储过程,传入参数为学生编号,根据学生编号查询记录,把该学生的所有的各门成绩写入到T_test表中,如果该学生在T_test表中已经存在做重复学生异常处理,则该成绩不写入T_test表中,如果该学生编号为错误编号则,做错误学生编号异常处理。
小弟最近才接触Oracle,这道题的异常处理研究半天也不知道该如何下手,请高手们给个简单明了的方法,以下是我写的前面的存储过程,后面异常一方面语法不是很清楚,另一方面也没有一个好的思路,恳请各位帮忙。
create or replace procedure Addnewtest(P_sid T_student.Sid%TYPE) is
begin
insert into t_Test
select a.sid,
a.sname,
b.classname,
t_curricula.cuname,
d.grade
FROM t_Student a,t_Class b,t_grade d,t_curricula
where d.sid=a.sid
AND a.classid=b.classid and t_curricula.cuid=d.cuid and a.sid=p_sid;
commit;
end Addnewtest;
小弟最近才接触Oracle,这道题的异常处理研究半天也不知道该如何下手,请高手们给个简单明了的方法,以下是我写的前面的存储过程,后面异常一方面语法不是很清楚,另一方面也没有一个好的思路,恳请各位帮忙。
create or replace procedure Addnewtest(P_sid T_student.Sid%TYPE) is
begin
insert into t_Test
select a.sid,
a.sname,
b.classname,
t_curricula.cuname,
d.grade
FROM t_Student a,t_Class b,t_grade d,t_curricula
where d.sid=a.sid
AND a.classid=b.classid and t_curricula.cuid=d.cuid and a.sid=p_sid;
commit;
end Addnewtest;
merge into t_Test
using (select a.sid, a.sname, b.classname, t_curricula.cuname, d.grade
FROM t_Student a, t_Class b, t_grade d, t_curricula
where d.sid = a.sid
AND a.classid = b.classid
and t_curricula.cuid = d.cuid
and a.sid = p_sid) b
on (a.sid = t_Test.sid)
when not matched then
insert values (b.sid, b.sname, b.cuname, b.grade)
create or replace procedure Addnewtest(P_sid T_student.Sid%TYPE) is
v_ret varchar2(32);
v_msg varchar2(32);
begin
insert into t_Test
select a.sid, a.sname, b.classname, t_curricula.cuname, d.grade
FROM t_Student a, t_Class b, t_grade d, t_curricula
where d.sid = a.sid
AND a.classid = b.classid
and t_curricula.cuid = d.cuid
and a.sid = p_sid;
---添加的异常处理
EXCEPTION
WHEN OTHERS THEN
v_ret := SQLCODE;
v_msg := SQLERRM(SQLCODE);
if (v_ret != 0) then
rollback;
elsif then
commit;
end if;
end Addnewtest;
http://school.itzcn.com/video-vid-1207-spid-35.html