mysql5.7存儲過程不明白爲什麼要把遊標判斷的放在declare其它變量的前面否則就要報錯

-- 存儲過程作用去除以.cn結尾的url後面的參數

create PROCEDURE g_sp()
begin
  declare done int default FALSE;
  declare tid int;
  declare gurl varchar(255);
  
-- 聲明遊標
    declare cur cursor for select id,url from t_crawler_config;
    -- 指定遊標循環結束時的返回值 
    declare continue handler for not found set done = TRUE;
    -- 打開遊標
    open cur;
    -- while 循環
    while done != 1 do
        fetch cur into tid,gurl;
          if done != 1 and LOCATE('.cn/',gurl)!=0 then
             set gurl=substring(gurl,1,LOCATE('.cn/',gurl)+3);
             update t_crawler_config set url=gurl where id=tid;
          end if;    
    end while;
    -- 關閉遊標
    close cur;
end

--調用存儲過程語句
call g_sp();
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章