当前位置:Gxlcms > 数据库问题 > 用navicat工具创建MySQL存储过程

用navicat工具创建MySQL存储过程

时间:2021-07-01 10:21:17 帮助过:5人阅读

  •     /* 定义变量 */  
  •     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 ;  
  •   
  •                 -- 可以加入insert,update等语句  
  •         
  •     /* 循环结束 */    
  •     end loop myLoop;    
  •         
  •     /* 关闭游标 */    
  •     close myCursor;    
  • END  
  •  

    4.保存(请输入合法名称):

    技术分享图片
     

    5.运行存储过程(在结果1,2,3...中可以查询输出信息):

    技术分享图片
     

    用navicat工具创建MySQL存储过程

    标签:etc   语句   mys   编写   函数标签   idt   png   退出   tin   

    人气教程排行