Manoj Muduli Manoj Muduli - 2 months ago 9
MySQL Question

How to use a mysql stored procedure result set in another stored procedure

I want to filter the result set returned by a stored procedure in side another stored procedure

Ex:

delimiter //
create procedure x()
begin
select 1 as a, 2 as b,3 as c;
end //


In y stored procedure I want to select only 'a' column value return from 'x' stored procedure

delimiter //
create procedure y()
begin

end//

Answer

Maybe this will help.

First get result from proc x into a temporary table tmp:

            delimiter //
            create procedure x()
            begin
            create temporary table `tmp`
            select 1 as a, 2 as b,3 as c;
            end //

then call proc x into proc y

            delimiter //
            create procedure y()
            begin
            call x();
            select a from tmp;
            end //

Finally call y() to result the field a from proc x select .

If you want to get only proc x result then run:

            call x();
            select * from tmp;
Comments