其實是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 //