存储过程3:加法
来源:互联网 发布:手机特效软件安卓版 编辑:程序博客网 时间:2024/06/08 19:42
drop procedure if exists pr_add; create procedure pr_add(in a int, in b int) begin declare c int; if a is null then set a = 0; end if; if b is null then set b = 0; end if; set c = a + b; select c as sum; end; // call pr_add(10, 20);//set @a = 10; set @b = 20; call pr_add(@a, @b); //drop procedure if exists pr_add; create procedure pr_add(in a int, in b int, out sum int) begin if a is null then set a = 0; end if; if b is null then set b = 0; end if; set sum = a + b; end; // call pr_add(10, 20, @sum);//select @sum;//
MySQL 存储过程参数如果不显式指定“in”、“out”、“inout”,则默认为“in”。习惯上,
对于是“in” 的参数,我们都不会显式指定。
MySQL 存储过程名字后面的“()”是必须的,即使没有一个参数,也需要“()”
MySQL 存储过程参数,不能在参数名称前加“@”,如:“@a int”。下面的创建存储过程
语法在 MySQL 中是错误的(在 SQL Server 中是正确的)。 MySQL 存储过程中的变量,不需要在变量名字前加“@”,虽然 MySQL 客户端用户变量要加个“@”。
create procedure pr_add
( @a int, -- 错误
b int -- 正确
)
因为 MySQL 存储过程参数没有默认值,所以在调用 MySQL 存储过程时候,不能省略参数。可以用 null 来替代。
比如
call pr_add(null, 20, @sum);//select @sum;//
结果是20
- 存储过程3:加法
- SQL 存储过程(3)
- 分页存储过程3
- 存储过程3
- 存储过程3
- 存储过程示例3
- oracle存储过程3
- 存储过程3
- oracle之存储过程3-执行存储过程
- oracle 存储过程基础知识3
- SQL的存储过程3
- MySql分页存储过程3
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 使用中文版man(shell帮助)
- 2011年全国大学生程序设计邀请赛(福州)——Tiling
- 法师VS战士PK小谈
- 简单的回射程序
- Python_博客自动访问脚本
- 存储过程3:加法
- 文件上传的渐进式增强
- MFC 无标题栏窗口最大化会把任务栏给遮住,如何解决这个问题?
- WebRTC源码分析4_AVI文件读写
- python _自动化性能测试脚本
- git remote
- 动态规划基础
- 弱校ACM奋斗史
- 基于SPP协议,通过iphone蓝牙与经过苹果MFI授权认证的硬件通讯,传输图片