Use mysql stored procedure result set in another stored procedure

I have a MYSQL SP1 () stored procedure that returns a result set.

I want to call SP1 () inside SP2 () and iterate over the result set SP1 () to do some extra work.

I do not want to include my logic from SP1 (), because it will make SP2 () too complicated.

Any suggestions?

Thank.

+3
source share
2 answers

What you want to do doesn’t sound very good, and maybe you should consider redesigning these 2 procs. However, you can do something like this as a quick fix:

sp2 sproc, , / sp1. , sp2, sp1.

http://pastie.org/883881

delimiter ;
drop procedure if exists foo;
delimiter #

create procedure foo()
begin

  create temporary table tmp_users select * from users;

  -- do stuff with tmp_users

  call bar();

  drop temporary table if exists tmp_users;

end #

delimiter ;

drop procedure if exists bar;

delimiter #

create procedure bar()
begin
  -- do more stuff with tmp_users
  select * from tmp_users;
end #

delimiter ;

call foo();

,

+4

.

, , SP1() .

0

Source: https://habr.com/ru/post/1737444/


All Articles