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...中可以查询输出信息):


     

  • 相关阅读:
    iOS开发多线程篇 03 —线程安全
    【Objective-C】01-Objective-C概述
    insert小细节,大问题
    高速修复汉澳sinox命令解释程序bash shell漏洞
    load-on-startup 解释
    研究下JavaScript中的Rest參数和參数默认值
    UVALive 6530 Football (水
    Android多线程分析之五:使用AsyncTask异步下载图像
    POJ2407_Relatives【欧拉phi函数】【基本】
    cocos2d-x 下使用加密 sqlite3
  • 原文地址:https://www.cnblogs.com/remember-forget/p/6211361.html
Copyright © 2011-2022 走看看