database - Mysql stored procedure issue in fetching record -


i have list of id's in array. want fetch details table "user" using id's.

i need stored procedure send array of id's , datails of each id in return array result.

you can try these ways:

  • a: use additional table, maybe temporary, store id values need in procedure, join table table(s).
  • b: pass id values string argument procedure, build result sql statement, , execute using mysql prepared statements.

example (case a):

delimiter $$ create procedure procedure1() begin   select * table1 t1 join table_id t2 on t1.id = t2.id; end$$ delimiter ;  create table table_id(id int(11)); insert table_id values(1),(2),(3),(4),(5);  call procedure1(); 

example (case b):

delimiter $$  create procedure procedure1(in id_param varchar(255)) begin   set @sql = concat('select * table id in (', id_param, ')');   prepare stmt @sql;   execute stmt;   deallocate prepare stmt; end$$  delimiter ;  set @id = '1,2,3,4,5'; call procedure1(@id); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -