您好,欢迎来到客趣旅游网。
搜索
您的当前位置:首页mysql使用存储过程返回多个值_MySQL

mysql使用存储过程返回多个值_MySQL

来源:客趣旅游网

bitsCN.com

mysql使用存储过程返回多个值

可以使用OUT、INOUT参数类型让存储过程返回多个结果值,存储函数不能胜任,因为只能返回一个值。比如统计student数据表里男生和女生人数并通过它的参数返回这两个计数值,让调用者可以访问它们:

[sql] 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] CALL count_students_by_sex(@mcount,@fcount); select 'Number of male students:',@mcount; 结果:Number of male studens: @mcountNumber of students: 16


bitsCN.com

Copyright © 2019- kqyc.cn 版权所有 赣ICP备2024042808号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务