problem using Oracle parameters in SELECT IN

前端 未结 3 1695
既然无缘
既然无缘 2020-11-30 13:12

I have a problem when inserting a string of numbers into sql query

  SELECT * 
    FROM tablename a 
   WHERE a.flokkurid IN (3857,3858,3863,3285) 
ORDER BY          


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 13:47

    That's not how parameters work. You cannot specify a "set" as a parameter, you have to assemble the SQL query in the string. And watch out for SQL Injection.

    In addition, you might want to take a look at these:

    • Is it possible to use query parameters to fill the IN keyword
    • Parameterize an SQL IN clause

    Update

    Codo's answer has a very interesting approach for Oracle. I cannot test it right now, but it sure looks promising.

    There's a very similar question here: OracleParameter and IN Clause , as pointed out by @DCookie. It's not an exact duplicate because when the type of the item in array changes, the SQL cast also changes.

提交回复
热议问题