Home > Database > Mysql Tutorial > mysql使用存储过程返回多个值

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:17:38
Original
1308 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 可以使用OUT、INOUT参数类型让存储过程返回多个结果值,存储函数不能胜任,因为只能返回一个值。比如统计student数据表里男生和女生人数并通过它的参数返回这两个计数值,让调用者可以访问它们: [sq

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  可以使用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: @mcount

  Number of students: 16

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template