温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

存储过程定义语法

发布时间:2020-08-04 19:10:56 来源:网络 阅读:400 作者:Lee_吉 栏目:MySQL数据库

CREATE  PROCEDURE `addTicket`(in vipsql VARCHAR(255),in ordersql VARCHAR(255),in detailkey varchar(255),in detailsql VARCHAR(255)) comment '挂单(售药窗口)'

BEGIN

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION ,NOT FOUND

rollback;

start transaction;

set @vid=@oid='';

set @outstr='';

set @errcode=200;

set @errmsg='成功';

if vipsql=0 then

set @tem=vipsql;

prepare tem from @tem;

execute tem;

set @rows=row_count();

if @rows<=0 then

set @errcode=501;

set @errmsg='插入到【会员表】失败';

rollback;

end if;

set @vid=LAST_INSERT_ID();

else

set @vid=vipsql;

end if;

select order_outpatient_num into @cnum from `order` order by order_outpatient_num desc limit 1;

if locate(curdate()+0,@cnum)=0||@cnum='' then

set @cnum=concat(curdate()+0,'00000001');

else

set @cnum=@cnum+1;

end if;

set ordersql=concat(ordersql,"'",@vid,"','",@cnum,"')");

set @ordersql=ordersql;

prepare temp from @ordersql;

execute temp;

set @rows=row_count();

if @rows<=0 then

set @errcode=502;

set @errmsg='插入到【订单表】失败';

rollback;

end if;

set @oid=LAST_INSERT_ID();

set @num=(length(detailsql)-length(replace(detailsql,'*#*','')))/3+1;

set @i=1;

while @i<=@num do

if @i=1 then

set @strsql=substring_index(detailsql,'*#*',@i);

else

set @strsql=substring_index(detailsql,'*#*',@i);

set @strsql=substring_index(@strsql,'*#*',-1);

end if;

set @outstr=concat(@outstr,@strsql,"'",@cnum,"','",@oid,"'),");

set @i=@i+1;

end while;

set @outstr=concat(detailkey,@outstr);

set @outstr=left(@outstr,char_length(@outstr)-1);

prepare temp0 from @outstr;

execute temp0;

set @rows=row_count();

if @rows<=0 then

set @errcode=503;

set @errmsg='插入到【订单详情表】失败';

rollback;

end if;

commit;

select @errcode as errcode,@errmsg as errmsg;

END

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI