2016-12-16 19 views
0

私は別のクエリから受け取っている値のセットでストアドプロシージャを呼び出そうとしています。どのようにして別のプロシージャを呼び出すことができますかクエリの値。ここに私のコードはMySQL特定の値を持つそれぞれの条件

CREATE DEFINER=`root`@`localhost` PROCEDURE `temp`(IN u_id int) 
BEGIN 

#below query will give me all the u_id values that i need to use(ex : 2,8,9) 
Declare cur cursor for select r_id from temp.usr_rl where u_id in (u_id); 

#below i would like to use the u_id values and run the below procedure in a loop for each value in u_id 
open cur; 
repeat 
    fetch cur into a; 
    if not done then 
     call get_r(a); 
    end if; 
until done end repeat;  

close cur; 
END 

答えて

0

それはあなたがすべてのレコードを処理し、別の手順を呼び出すためにカーソルを使用しているので、巨大なパフォーマンスヒットが発生します。したがって、あなたは実際に効果を倍増させています。代わりに、Temporary Tableにすべての値をフェッチして保存し、以下のようにCTASを使用して、処理中のものはcall get_rのプロシージャ内からその一時テーブルにアクセスしてください。

create temporary table myTemp 
as select r_id from temp.usr_rl where u_id = u_id; 
関連する問題