MySQL里用存储过程实现加减乘除
来源:互联网 发布:链轮厚度计算软件 编辑:程序博客网 时间:2024/06/12 00:26
MySQL从5.0版本开始支持存储过程procedure,下面介绍在MySQL5.1中使用存储过程实现整数的加减乘除。
创建存储过程时,需要依赖某个数据库,可以任意指定,比如数据库shop。
1.用存储过程实现整数相加
use shop;delimiter $create procedure addNum(in a int, in b int)begindeclare res int default 0;if a is null then set a=0;end if;if b is null then set b=0;end if;/* a+b */set res=a+b;/* output the result */select res;end;$delimiter ;
2.用存储过程实现整数相减
use shop;delimiter $create procedure subNum(in a int, in b int)begindeclare res int default 0;if a is null then set a=0;end if;if b is null then set b=0;end if;/* a-b */set res=a-b;/* output the result */select res;end;$delimiter ;
3.用存储过程实现整数相乘
use shop;delimiter $create procedure multiNum(in a int, in b int)begindeclare res int default 0;if a is null then set a=0;end if;if b is null then set b=0;end if;/* a*b */set res=a*b;/* output the result */select res;end;$delimiter ;
4.用存储过程实现整数相除
use shop;delimiter $create procedure divNum(in a int, in b int)begin/* res is float */declare res float default 0;if a is null then set a=0;end if;if b is null then set b=0;end if;/* a/b */if b=0 then set res=null;else set res=a/b;end if;/* output the result */select res; end;$delimiter ;
整数3/5=0.6,效果如下:
调用存储过程,对两个整数进行加减乘除运算的效果,分别如图(2)所示:
5.查看当前数据库里所有的存储过程
show procedure status;
6.查看某个存储过程
show create procedure your_proce_Name
/* 比如:*/show create procedure addNum;
7.删除当前数据库的某个存储过程
drop procedure your_proce_Name;
/* 比如 */drop procedure addNum;
1 0
- MySQL里用存储过程实现加减乘除
- 存储过程学习-加减乘除
- MYSQL命令行里创建存储过程(初级)
- 用mysql的存储过程实现生成唯一订单号
- MySQL存储过程里字符串拼接返回参数的方法
- 在MYSQL里教你写一个存储过程
- mysql数据库存储过程学习实现分页
- MYSQL存储过程实现分页并显示
- JAVA调用MYSQL存储过程实现分页
- mysql存储过程实现无限分类
- MySql 运用存储过程实现主键生成
- Java实现mysql存储过程调用
- MySQL存储过程实现批量插入数据
- mysql 存储过程实现事务方法
- MYSQL 数据行列交换 存储过程实现
- mysql数据库存储过程学习实现分页
- Java实现mysql存储过程调用
- MySQL 使用存储过程实现留存率
- 为ffmpeg添加自定义滤镜
- springmvc程序启动时候抛异常
- ffmpeg超详细综合教程二——为直播流添加滤镜
- Java虚拟机学习之走进 Java
- unix/linux 系统管理员的工作内容
- MySQL里用存储过程实现加减乘除
- 学习php的个人经验
- 在eclipse中如何查阅源代码
- Android日历(Calendar,dataPicker)
- Java虚拟机学习之 代码编译和执行的整个过程
- Navicat_for_MySQL_10.0.5 注册码
- 学习程序的那些事儿
- Internet命名规则和地址划分约定
- hadoop2.4.1完全分布式搭建