MYSQL存储过程和调用
工作中用到的逻辑写成存储过程来用
CREATE PROCEDURE `pro_getLibCount`(IN qtype INTEGER(11),IN qdesc varchar(50),IN qversion varchar(50),IN qname varchar(50),IN qpath varchar(50),IN qxml varchar(50),OUT libcount INTEGER(11))
BEGIN
select count(question_id) into libcount from t_question_library where question_version = qversion;
begin
if(libcount=0) then
insert into t_question_library (question_type,question_desc,question_version,file_name,file_path,question_xml)
values(qtype,qdesc,qversion,qname,qpath,qxml);
set libcount=last_insert_id();
else
select question_id into libcount from t_question_library where question_version = qversion;
end if;
end;
END
调用
call pro_getLibCount('3','part1_Q1','0BFDBF7D911FA8C6B28B1E20491B46B9','0BFDBF7D911FA8C6B28B1E20491B46B0.LPK','http://10.10.66.206/questionlibrary/','1-1.xml',@library);
insert into t_paperquestion_library (paper_question_id,question_id) values('1',@library);