0

I have stored procedure like

    CREATE DEFINER=`test`@`%` PROCEDURE  `test`.`get_details`(
    in p_istudid int,
    in p_icourseid int,
    in p_branchid varchar(20)
    )
    BEGIN
    select ...
    ...
    and branch.id in(p_branchid);
    END

I want to pass comma separated values to 3rd parameter, how to pass that values? I tried like -

 call get_details(10,11,'20,30');

but is only showing records have branch id 20, not 30.

Thanx in advance.

Sid
  • 11
  • 2
  • 9
  • Possible duplicate of [prepare statement to pass comma-separated values to stored procedure parameter](http://stackoverflow.com/questions/25508686/prepare-statement-to-pass-comma-separated-values-to-stored-procedure-parameter) – Husam Nov 06 '15 at 07:18
  • Possible duplicate of [MySQL variable format for a "NOT IN" list of values](https://stackoverflow.com/questions/11957643/mysql-variable-format-for-a-not-in-list-of-values) – Ivan Olshansky Nov 19 '18 at 19:02

1 Answers1

4

You can pass comma separated values in procedures however you need to use prepared statement to use it, since the values you pass should be concatenated in the query.

delimiter //
   CREATE DEFINER=`test`@`%` PROCEDURE  `test`.`get_details`(
    in p_istudid int,
    in p_icourseid int,
    in p_branchid varchar(20)
    )
    BEGIN
    set @qry = concat('select .... and branch.id in (\'',p_branchid,'\')');
    prepare stmp from @qry;
    execute stmp ;
    deallocate prepare stmp;
    END;//
delimiter ;
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63