1、必须给数据库用户super权限,否则无法执行存储过程。用root用户创建的存储过程,其他用户在调用时必须在数据库url上加上参数,比较完整的url如下:
jdbc:mysql://10.28.79.2:3306/cbbt?noAccessToProcedureBodies=true
2、在存储过程中的select中使用in子句,以及select返回多条记录的时候的处理方法
BEGIN
DEClare qid,qtype,qscore int;
DECLARE stopFlag int DEFAULT 0;
DECLARE qtitle,qoa,qob,qoc,qod,qans varchar(1000);
DECLARE qnum int DEFAULT 1;
#定义游标
DECLARE Que_ResultSet CURSOR FOR select tid,title,optiona,optionb,optionc,optiond,type,answer,score,type from problems WHERE FIND_IN_SET(tid,ids) ORDER BY tid;
DECLARE CONTINUE HANDLER FOR NOT FOUND set stopFlag=1;
set stopFlag=0;
OPEN Que_ResultSet;
REPEAT
FETCH Que_ResultSet INTO qid,qtitle,qoa,qob,qoc,qod,qtype,qans,qscore,qtype;
IF NOT stopFlag then #没有这行的话,最后一条记录会重复两次
BEGIN
if qtype=1 or qtype=2 THEN
insert into panswer(paperid,problemid,answer,score,type) values(pid,qnum,qans,qscore,qtype);
ELSE
insert into panswer(paperid,problemid,answer,score,type) values(pid,qnum,qoa,qscore,qtype);
end IF;
set qnum=qnum+1;
END;
end if;
UNTIL stopFlag = 1 END REPEAT;
CLOSE Que_ResultSet;
select tid,title,optiona,optionb,optionc,optiond,type from problems WHERE FIND_IN_SET(tid,ids) ORDER BY tid;
END
没有评论:
发表评论