Mysql uses the stored procedure to return multiple values

Source: Internet
Author: User
Mysql uses the stored procedure to return multiple values. The OUT And INOUT parameter types allow the stored procedure to return multiple results. Therefore, the stored function cannot be competent because only one value can be returned. For example, count the number of boys and girls in the student data table and return these two counts using its parameters, so that the caller can access them: delimiter $ createprocedurecount_s

Mysql uses the stored procedure to return multiple values. The OUT And INOUT parameter types allow the stored procedure to return multiple results. Therefore, the stored function cannot be competent because only one value can be returned. For example, count the number of boys and girls in the student data table and return these two counts using its parameters, so that the caller can access them: delimiter $ create procedure count_s

Mysql returns multiple values using Stored Procedures

You can use the OUT and INOUT parameter types to allow the stored procedure to return multiple result values. The stored function is not competent because only one value can be returned. For example, count the number of boys and girls in the student data table and return these two count values through its parameters, so that the caller can access them:

delimiter $$create procedure count_students_by_sex(out p_male int ,out p_female int)beginselect  count(*) from student where sex= 'M' into p_male;select count(*) from student where sex='F' into p_feamle;end $$delimiter ;


When calling this process, replace the parameter with the custom variable. For example:

CALL count_students_by_sex(@mcount,@fcount);select 'Number of male students:',@mcount;


Result:

Number of male studens: @ Mcount
Number of students: 16

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.