mysql存储过程几个小案例
来源:互联网 发布:软件系统租用合同范本 编辑:程序博客网 时间:2024/06/05 19:55
#存储过程的学习!!!!!!!
一、入门案例的学习
DROP PROCEDURE IF EXISTS proc_aa; ##删除已经存在的过程
DELIMITER //
CREATE PROCEDURE `proc_aa`(IN a int,IN b int,OUT c int)
BEGIN
DECLARE temp int;
if a is null then set a = 1;
ELSE set a = a;
end if;
if b is null then set b = 1;
ELSE set b = b;
end if;
set temp = a + b;
set c = temp;
END
//
DELIMITER ;
#调用
SET @a = 29;
set @b = 33;
set @c = 44;
call proc_aa(@a,@b,@c);
select @c;
二、表操作
2.1 查询
delimiter//
drop procedure if exists sp//
CREATE PROCEDURE sp() select * from user //
call sp()//
DELIMITER;
2.2 插入数据
delimiter//
drop procedure if exists cc//
CREATE PROCEDURE cc(IN id int ,In age int)
begin
insert into user (id,age) VALUES(id,age);
end
//
DELIMITER;
set @id = 333;
set @age = 444;
call cc(@id,@age);
2.3 更新数据
delimiter//
drop procedure if exists dd//
CREATE PROCEDURE dd(IN id int)
begin
update user set age = 444 where `user`.id = id;
end
//
DELIMITER;
set @id = 333;
call dd(@id);
三、流程控制语句
3.1 if then ; elseif then ; else ;end if;
DELIMITER //
drop procedure if exists proc_if//
create procedure proc_if(IN type int)
BEGIN
declare c varchar(500);
IF type = 0 THEN
set c = '参数是 0';
ELSEIF type = 1 THEN
set c = '参数是 1';
else
set c = '参数不是 1和0';
end if;
select c;
end
//
DELIMITER;
set @a = '33';
call proc_if(@a);
3.2 case when then ; when then ; else ; end case;
DELIMITER //
drop procedure if exists proc_if//
create procedure proc_if(IN type int)
BEGIN
declare c varchar(500);
case when type = 0 THEN
set c = '参数是 0';
when type = 1 THEN
set c = '参数是 1';
else
set c = '参数不是 1和0';
end case;
select c;
end
//
DELIMITER;
set @a = '33';
call proc_if(@a);
一、入门案例的学习
DROP PROCEDURE IF EXISTS proc_aa; ##删除已经存在的过程
DELIMITER //
CREATE PROCEDURE `proc_aa`(IN a int,IN b int,OUT c int)
BEGIN
DECLARE temp int;
if a is null then set a = 1;
ELSE set a = a;
end if;
if b is null then set b = 1;
ELSE set b = b;
end if;
set temp = a + b;
set c = temp;
END
//
DELIMITER ;
#调用
SET @a = 29;
set @b = 33;
set @c = 44;
call proc_aa(@a,@b,@c);
select @c;
二、表操作
2.1 查询
delimiter//
drop procedure if exists sp//
CREATE PROCEDURE sp() select * from user //
call sp()//
DELIMITER;
2.2 插入数据
delimiter//
drop procedure if exists cc//
CREATE PROCEDURE cc(IN id int ,In age int)
begin
insert into user (id,age) VALUES(id,age);
end
//
DELIMITER;
set @id = 333;
set @age = 444;
call cc(@id,@age);
2.3 更新数据
delimiter//
drop procedure if exists dd//
CREATE PROCEDURE dd(IN id int)
begin
update user set age = 444 where `user`.id = id;
end
//
DELIMITER;
set @id = 333;
call dd(@id);
三、流程控制语句
3.1 if then ; elseif then ; else ;end if;
DELIMITER //
drop procedure if exists proc_if//
create procedure proc_if(IN type int)
BEGIN
declare c varchar(500);
IF type = 0 THEN
set c = '参数是 0';
ELSEIF type = 1 THEN
set c = '参数是 1';
else
set c = '参数不是 1和0';
end if;
select c;
end
//
DELIMITER;
set @a = '33';
call proc_if(@a);
3.2 case when then ; when then ; else ; end case;
DELIMITER //
drop procedure if exists proc_if//
create procedure proc_if(IN type int)
BEGIN
declare c varchar(500);
case when type = 0 THEN
set c = '参数是 0';
when type = 1 THEN
set c = '参数是 1';
else
set c = '参数不是 1和0';
end case;
select c;
end
//
DELIMITER;
set @a = '33';
call proc_if(@a);
阅读全文
0 0
- mysql存储过程几个小案例
- mysql存储过程案例
- 存储过程 mysql 案例
- Mysql存储过程案例
- mysql 存储过程小例子
- mysql小技巧、存储过程
- MySql 存储过程小例子
- mysql存储过程小例子
- Mysql 存储过程小例子
- mysql存储过程小例
- mysql 存储过程 小事例
- MYSQL 存储过程和函数 案例 例子
- sql server存储过程 以及几个常用案例
- MySQL 触发器 存储过程 一点小用
- MySql 存储过程 IF ElSE 小实例
- MySql 存储过程 IF ElSE 小实例
- mysql带参存储过程小例子
- mysql存储过程事务处理小经验
- LinuxMint轻松解决TXT文本乱码问题
- 大话遗传算法(含Matlab代码)
- 修改Request的请求路径
- 会话技术 Cookie&Session
- Python基础教程第八章学习笔记——异常
- mysql存储过程几个小案例
- Spring的环境搭建与注入
- hadoop文件上传解析
- linux下ffmpeg安装
- Objective-C的内省
- hackerrank Lucky Numbers(扩展gcd/规律)
- C语言编程代码架构搭建——代码分层
- Linux下ffmpeg的完整安装
- 使用MySQL Workbench进行数据库设计——MySQL Workbench使用方法总结