mysql的循環(huán)語句問題
問題描述
要多次的執(zhí)行一個(gè)select操作,就想著用循環(huán)來實(shí)現(xiàn),在網(wǎng)上查了一些內(nèi)容,顯示的做法都是差不多的,就是總是提示語言錯(cuò)誤,很是郁悶,各位大俠幫忙看看,要怎么改才可以。mysql數(shù)據(jù)庫、navicat客戶端。mysql循環(huán)的操作語句:
procedure pro10()begindeclare i int; set i=0; while i<5 do select * from gamechannel where status=i GROUP BY gameId ; set i=i+1; end while;end;
錯(cuò)誤信息:[SQL] procedure pro10()begindeclare i int;[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’procedure pro10()begindeclare i int’ at line 1
問題解答
回答1:你這是再寫存儲(chǔ)過程嗎?1.創(chuàng)建存儲(chǔ)過程DELIMITER $$create procedure pro10()begindeclare i int; set i=0; while i<5 do
select * from gamechannel where status=i GROUP BY gameId ; set i=i+1;
end while;end;$$
2.調(diào)用call pro10()
相關(guān)文章:
1. javascript - 百度echarts series數(shù)據(jù)更新問題2. MySQL客戶端吃掉了SQL注解?3. java - 我設(shè)置了cookie的max age,但是cookie依然在關(guān)閉游覽器后消失了4. css3 - [CSS] 動(dòng)畫效果 3D翻轉(zhuǎn)bug5. javascript - JS設(shè)置Video視頻對(duì)象的currentTime時(shí)出現(xiàn)了問題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...6. python小白的基礎(chǔ)問題 關(guān)于while循環(huán)的嵌套7. java固定鍵值轉(zhuǎn)換,使用枚舉實(shí)現(xiàn)字典?8. php自學(xué)從哪里開始?9. phpstady在win10上運(yùn)行10. 求大神幫我看看是哪里寫錯(cuò)了 感謝細(xì)心解答
