zoukankan      html  css  js  c++  java
  • Mysql高级编程_存储过程类型(in/out/inout)

    简单实例:

    ------>存储过程,参数的传入!
    delimiter $
    create procedure p1()
    begin
        declare  i int default 10;
        select concat ('i的取值是:',i) as QuZhi;
    end $
    
    delimiter $
    create procedure p2(width int, hegit int)
    begin
        select concat('它的面积是:',width * hegit) as area;
        if width > hegit then
            select '比较瘦' as Xingzhuang ;
        elseif width < hegit then
            select '比较方' as Xingzhuang ;
        end if;
    end $
    
    
    
    ------>这里求的是1+100之间的和,这里是固定的求和
    delimiter $
    create procedure p3()
    begin
        declare total int default 0 ;
        declare num   int default 0 ;
        while num <= 100 do
            set total := total+num;
            set num := num +1;
        end while;
        select concat('total的大小是:',total) as total;
    end $
    
    --->需求:如果这里想要计算1+N ?
    --->in型参数表示往存储过程中传输参数
    delimiter $
    create procedure p4(in n int)  
    begin
        declare total int default 0 ;
        declare num   int default 0 ;
        while num <= n do
            set total := total+num;
            set num := num +1;
        end while;
        select concat('total的大小是:',total) as total;
    end $
    
    ---看看out型参数?
    create procedure p5(in n int,out total int)  
    begin
        declare num   int default 0 ;
        set total := 0;
        while num <= n do
            set total := total+num;
            set num := num +1;
        end while;
        
    end $
    
    --看看inout型参数?
    delimiter $
    create procedure p6(inout age int)
    begin
        set age := age + 10;
    end $
    
    --具体操作--
    root@localhost 22:57:  [liulin]> set @current=18 $      --这里先要设置一个变量--
    Query OK, 0 rows affected (0.00 sec)
    
    root@localhost 22:58:  [liulin]> call p6(@current) $    --然后再将这个变量传入存储过程中inout类型中--
    Query OK, 0 rows affected (0.00 sec)
    
    root@localhost 22:58:  [liulin]> select @current $      --最后再查看该变量是否修改--
    +----------+
    | @current |
    +----------+
    |       28 |
    +----------+
    1 row in set (0.00 sec)
  • 相关阅读:
    微信小程序分享及信息追踪
    vue刷新路由,不刷新页面
    vue中是使用富文本编辑器vue-quill-edit
    下载配置nodeJs,cnpm,webpack,vue-cli等,刚装的系统,所有东西重新配置
    promise学习总结
    【转】前端的BFC、IFC、GFC和FFC
    ES6中export与export default的区别
    前端常见跨域解决方案
    vue2.0s中eventBus实现兄弟组件通信
    RHEL5 yum更新源
  • 原文地址:https://www.cnblogs.com/zmc60/p/14673274.html
Copyright © 2011-2022 走看看