MySQL Forums
Forum List  »  Newbie

Re: Table-valued parameters to a stored procedure
Posted by: Peter Brawley
Date: December 10, 2021 08:24PM

Scott, is this what you mean?

drop procedure if exists str2table;
delimiter go
create procedure str2table( ptxt text )
begin
  drop temporary table if exists t;
  create temporary table t( txt text );
  insert into t values( ptxt );
  drop temporary table if exists temp;
  create temporary table temp( val char(255) );
  set @sql = concat( "insert into temp (val) values ('", 
                     replace(( select group_concat(distinct txt) as data from t), 
                     ",", "'),('"),"');"
                   );
  prepare stmt1 from @sql;
  execute stmt1;
 end;
go
delimiter ;
call str2table( '1,2,3,4,5,6,7,8,9' );
select * from temp;



Edited 1 time(s). Last edit at 12/10/2021 08:26PM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
Re: Table-valued parameters to a stored procedure
December 10, 2021 08:24PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.