使用Navicat for MySQL工具建立存儲過程步驟:html
1. 新建函數(選擇函數標籤 -> 點擊新建函數):mysql

2.輸入函數的參數個數、參數名、參數類型等:sql

3.編寫存儲過程:函數

代碼以下:工具
- BEGIN
- /* 定義變量 */
- declare tmp0 VARCHAR(1000);
- declare tmp1 VARCHAR(1000);
- declare done int default -1;
-
- /* 聲明遊標 */
- declare myCursor cursor for select cell_0,cell_1 from t_test;
-
- /* 當遊標到達尾部時,mysql自動設置done=1 */
- declare continue handler for not found set done=1;
-
- /* 打開遊標 */
- open myCursor;
-
- /* 循環開始 */
- myLoop: LOOP
-
- /* 移動遊標並賦值 */
- fetch myCursor into tmp0,tmp1;
-
-
- if done = 1 then
- leave myLoop;
- end if;
-
- /* do something */
-
- select tmp0,tmp1 ;
-
-
-
- /* 循環結束 */
- end loop myLoop;
-
- /* 關閉遊標 */
- close myCursor;
- END
4.保存(請輸入合法名稱):oop

5.運行存儲過程(在結果1,2,3...中能夠查詢輸出信息):fetch

來源:https://www.cnblogs.com/remember-forget/p/6211361.htmlspa