溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

存儲過程定義語法

發(fā)布時間:2020-08-04 19:10:56 來源:網(wǎng)絡(luò) 閱讀:399 作者:Lee_吉 欄目:MySQL數(shù)據(jù)庫

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問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI