MySQL的存储过程联系

BEGIN
    #Routine body goes here...
    declare tmp0 VARCHAR(1000);  
    declare tmp1 VARCHAR(1000);
   declare done int default -1;-- 用于控制循环是否结束 
  /* 声明游标 */ 
  declare myCursor cursor for select name,address from ads_building_info;
  /* 当游标到达尾部时,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 */ 
      -- 循环输出信息
      insert into test_demo (name,address) VALUES (tmp0,tmp1);
    end loop myLoop;
 close myCursor;
END

 

上一篇:sqlserver游标概念与实例全面解说


下一篇:SQL工作笔记-达梦7存储过程中游标的使用(for循环 IF等)