mysql命令行執(zhí)行創(chuàng)建存儲過程報錯

其實是mysql ;(分號的問題)。
可以采用delimiter //解決問題

image.png

然后回車,那么MySQL將立即執(zhí)行該語句。
但有時候,不希望MySQL這么做。在為可能輸入較多的語句,且語句中包含有分號。比如說我想創(chuàng)建一個存儲過程

CREATE PROCEDURE `count_orthopedic`(in column_id VARCHAR(20))
begin
 declare sample_count int default 0;
 declare count_pre_t int default 0;
 declare count_tn int default 0;
 declare count_fn int default 0;
 declare count_fp int default 0;
 declare count_tp int default 0;

 select count(1) from model_orthopedic_column_log m where m.column_id=column_id into sample_count;
 select count(1) from model_log where model_type = '10' and score ='1' into count_pre_t;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='0' into count_tn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='0' into count_fn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='1' into count_fp;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='1' into count_tp;

 select 1 'id',sample_count, count_pre_t,count_tn,count_fn,count_fp,count_tp;
end

這時候就一定會報錯了,以為mysql檢索到分號,就會執(zhí)行sql語句,這里我們來告訴mysql,檢索到//再執(zhí)行,也就是修改成以下,在sql執(zhí)行的末尾,加上"http://"。

delimiter //
CREATE PROCEDURE `count_orthopedic`(in column_id VARCHAR(20))
begin
 declare sample_count int default 0;#樣本數(shù)
 declare count_pre_t int default 0;#預測好轉(zhuǎn)數(shù)
 declare count_tn int default 0;
 declare count_fn int default 0;
 declare count_fp int default 0;
 declare count_tp int default 0;

 select count(1) from model_orthopedic_column_log m where m.column_id=column_id into sample_count;
 select count(1) from model_log where model_type = '10' and score ='1' into count_pre_t;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='0' into count_tn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='0' into count_fn;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 0 and ml.model_type = '10' and ml.score ='1' into count_fp;
 select count(1) from model_log ml inner join model_orthopedic_column_log m on ml.id = m.model_id  where m.column_id=column_id and m.res = 1 and ml.model_type = '10' and ml.score ='1' into count_tp;

 select 1 'id',sample_count, count_pre_t,count_tn,count_fn,count_fp,count_tp;
end //
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容