一个简单的存储过程
BEGINselect * from sell where depot_id in(_depot_id);END过程名为:abc
depot_id 为 int
请问怎么用 call 调用才正确呢?call abc('0,1,7') 结果不正确
call abc(1) 或 call abc('1') 正确怎么调用才能让  call abc('0,1,7') 的结果正确呢?

解决方案 »

  1.   

    用动态sql 或者 find_in_set函数
      

  2.   

    IN 没有办法,改成如下。select * from sell where FIND_IN_SET(depot_id,_depot_id);
      

  3.   

    IN必须用动态执行的方法
    prepare qq from @ee
    execute qqor用INSTR、FIND_IN_SET
      

  4.   

    create procedure abc
    (
    in _depot_id varchar(500)
    )
    begin
    select * from sell where find_in_set in(depot_id, _depot_id) > 0; 
    end;
      

  5.   

    或:create procedure abc
    (
    in _depot_id varchar(500)
    )
    begin
    set @str=concat('select * from sell where depot_id in (',_depot_id,')'; 
    prepare st from @str;
    execute st;
    deallocate prepare st;
    end;
      

  6.   

    MYSQL存储过程中直接执行的SQL是不支持动态参数的,你只能用动态SQL来实现,来实现
    create procedure abc(in _depot_id varchar(500))
    begin
        set @tmpsql=concat('select * from sell a where a.depot_id in (',_depot_id,')'); 
        prepare sqlstr from @tmpsql;
        EXECUTE strsql ;
    end;