zoukankan      html  css  js  c++  java
  • 使用navicat工具创建MySQL存储过程

    使用Navicat for MySQL工具创建存储过程步骤:

    1. 新建函数(选择函数标签 -> 点击新建函数):

    2.输入函数的参数个数、参数名、参数类型等:


     

    3.编写存储过程:


     代码如下:

    Sql代码  收藏代码
    1. BEGIN   
    2.     /* 定义变量 */  
    3.     declare tmp0 VARCHAR(1000);  
    4.     declare tmp1 VARCHAR(1000);  
    5.     declare done int default -1;  -- 用于控制循环是否结束  
    6.         
    7.     /* 声明游标 */    
    8.     declare myCursor cursor for select cell_0,cell_1 from t_test;    
    9.         
    10.     /* 当游标到达尾部时,mysql自动设置done=1 */       
    11.     declare continue handler for not found set done=1;    
    12.         
    13.     /* 打开游标 */    
    14.     open myCursor;    
    15.         
    16.     /* 循环开始 */    
    17.     myLoop: LOOP    
    18.         
    19.         /* 移动游标并赋值 */    
    20.         fetch myCursor into tmp0,tmp1;    
    21.           
    22.                 -- 游标到达尾部,退出循环  
    23.         if done = 1 then     
    24.         leave myLoop;    
    25.         end if;    
    26.             
    27.         /* do something */    
    28.         -- 循环输出信息  
    29.                 select tmp0,tmp1 ;  
    30.   
    31.                 -- 可以加入insert,update等语句  
    32.         
    33.     /* 循环结束 */    
    34.     end loop myLoop;    
    35.         
    36.     /* 关闭游标 */    
    37.     close myCursor;    
    38. END  

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


     

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

  • 相关阅读:
    css属性设置
    自由从摇篮开始 ——杨支柱
    提醒幸福
    随记
    那些回不去的年少时光(桐华)
    Javascript 与正则表达式
    XmlHttpRequest对象的获取及相关操作
    CSS的4种引入方式及优先级
    c#textBox控件限制只允许输入数字及小数点,是否为空
    c# 循环界面控件
  • 原文地址:https://www.cnblogs.com/gaopeng527/p/4447607.html
Copyright © 2011-2022 走看看