Mysql高级编程_存储过程类型(in/out/inout)
2021/4/18 19:27:02
本文主要是介绍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)
这篇关于Mysql高级编程_存储过程类型(in/out/inout)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-29阿里 Canal 实时同步 MySQL 增量数据至 ClickHouse 数据库
- 2024-05-24在Linux下管理MySQL的大小写敏感性
- 2024-04-26MySQL查出时间比实际晚8小时的解决方案
- 2024-04-01JPA不识别MySQL的枚举类型
- 2024-03-30mysql数据库表卡死解决方法
- 2024-03-15MySQL多数据源笔记5-ShardingJDBC实战
- 2024-03-11natural join mysql
- 2024-03-11关于VS2017,VS2015 中利用 EF使用Mysql 不显示数据源问题解决方案
- 2024-02-26mysql 阿里云xb后缀备份文件恢复-icode9专业技术文章分享
- 2024-02-22docker mysql 5.7