Add List to a mysql parameter

后端 未结 9 1316
暗喜
暗喜 2020-12-14 02:36

I have this question about the MySqlParameter from the .NET connector.

I have this query:

SELECT * FROM table WHERE id IN (@parameter)
9条回答
  •  佛祖请我去吃肉
    2020-12-14 03:22

    Answer from Mud only works for the first int in the parameter list. This means '2,1,3,4' won't work if id is 1 for example.

    See FIND_IN_SET() vs IN() .

    No comment possible by now but also see answer from Matt Ellen. Would edit his answer but can't. INSTR doesn't seem to work in a WHERE case with more than one id (returns only on result).

    But replacing INSTR with LOCATE make his solution work (with String.Join(",", intArray) as parameter added) ... UP VOTE from me:

    LOCATE(CONCAT(',' , CAST(id AS CHAR) , ',') , CONCAT(',' , CAST(@paramter AS CHAR) , ',')) <> 0
    

提交回复
热议问题