zoukankan      html  css  js  c++  java
  • 存储过程的参数

    存储过程传参:存储过程的括号里,可以声明参数。 语法是:create procedure p([in/out/inout] 参数名 参数类型 ..),MySQL 存储过程参数如果不显式指定in、out、inout,则默认为in

    in:传入function的参数

    create procedure p7(in n int)
    begin
        declare num int default 0;
        declare total int default 0;
    
        while num <=n do
            set total := total + num;
            set num := num + 1;
        end while;
    
        select total;
    end$

    调用:call(100)-------->5050(1+2+3+....+100)/call(10)--------------->55(1+2+3+.........+10)

    out:可以理解为某个function要改变的外部变量,不管这个变量在外部是什么值,在内部的初始值都是null,而内部对它的影响将改变这个外部变量值,即函数计算得到的值映射到函数外部

    create procedure p8(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$

    调用:call p8(10,@c);   select @c;----------------->打印55

    inout:为一个function在内部声明了global ,并可能对该变量值进行修改

    create procedure p9(inout age int)
    begin
        set age := age + 20;
    end$

    调用:set @age := 20;    call p9(@age);    select @age;     打印40      

  • 相关阅读:
    python 基础第二篇
    python 基础第五篇
    python 基础第四篇
    购物小编程(完整编码)
    计算机 python概论
    str 相关操作
    python 基础第三篇
    Nginx 配置多站点vhost
    h5页面宽度设置7.5rem
    js 倒计时,转义
  • 原文地址:https://www.cnblogs.com/lzxl/p/4198543.html
Copyright © 2011-2022 走看看