当前位置:Gxlcms > 数据库问题 > Mysql高级编程_存储过程类型(in/out/inout)

Mysql高级编程_存储过程类型(in/out/inout)

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

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)

 

Mysql高级编程_存储过程类型(in/out/inout)

标签:编程   localhost   mys   ota   begin   class   current   参数表   变量   

人气教程排行