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 |