mysql使用存储过程返回多个值
2016-08-07 23:16
176 查看
可以使用OUT、INOUT参数类型让存储过程返回多个结果值,存储函数不能胜任,因为只能返回一个值。比如统计student数据表里男生和女生人数并通过它的参数返回这两个计数值,让调用者可以访问它们:
[sql] view
plain copy
delimiter $$
create procedure count_students_by_sex(out p_male int ,out p_female int)
begin
select count(*) from student where sex= 'M' into p_male;
select count(*) from student where sex='F' into p_feamle;
end $$
delimiter ;
在调用这个过程的时候,把参数替换为用户自定义变量。如:
[sql] view
plain copy
CALL count_students_by_sex(@mcount,@fcount);
select 'Number of male students:',@mcount;
结果:
[sql] view
plain copy
delimiter $$
create procedure count_students_by_sex(out p_male int ,out p_female int)
begin
select count(*) from student where sex= 'M' into p_male;
select count(*) from student where sex='F' into p_feamle;
end $$
delimiter ;
在调用这个过程的时候,把参数替换为用户自定义变量。如:
[sql] view
plain copy
CALL count_students_by_sex(@mcount,@fcount);
select 'Number of male students:',@mcount;
结果:
Number of male studens: | @mcount |
Number of students: | 16 |
相关文章推荐
- asp.net调用mysql 存储过程 带 out 返回值,返回刚插入数据库中的自增的ID,LAST_INSERT_ID() 的使用
- mysql使用存储过程返回多个值
- asp.net调用mysql 存储过程 带 out 返回值,返回刚插入数据库中的自增的ID,LAST_INSERT_ID() 的使用
- Mysql中使用存储过程返回查询多个表的数据信息
- 使用有返回参数的存储过程
- mysql 中使用存储过程
- 在t-sql语句中使用存储过程返回的结果集
- MYSQL使用存储过程插入中文数据的疑似bug(UTF8)
- MYSQL使用存储过程插入中文数据的疑似bug(UTF8)
- 使用存储过程并返回值与及返回值的获得方法
- (转)SqlHelper 使用中需要注意的一点(带输出、返回参数的存储过程)
- 使用存储过程并返回值与及返回值的获得方法
- 使用存储过程返回一个数据集
- MySQL 5.0 存储过程例子(使用了游标)
- mysql 中使用存储过程
- 使用存储过程并返回值与及返回值的获得方法
- c#中如何使用存储过程的返回值
- 使用存储过程并返回值与及返回值的获得方法
- vb 6.0 使用存储过程返回的结果集
- php调用mysql存储过程返回多个结果集的处理