Add List to a mysql parameter

后端 未结 9 1281
暗喜
暗喜 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:18

    This doesn't work well for huge lists, but it is the only thing I have found that works if you have to pass a list in as a parameter.

    Instead of

    SELECT * FROM table WHERE id IN (@parameter)
    

    You have to do this:

    SELECT *
    FROM table
    WHERE INSTR(','+@parameter+',', ','+CAST(the_column AS CHAR) + ',')
    

    Then you can pass in your list with string.Join(",", intArray)

    It's a kludge, but it works.

提交回复
热议问题