problem using Oracle parameters in SELECT IN

前端 未结 3 1696
既然无缘
既然无缘 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:48

    To pass a set of values, you need to use Oracle's table or array types.

    At first, you create a table type (e.g. for NUMBER):

    CREATE TYPE number_table AS TABLE OF NUMBER; 
    

    When you create the parameter for the query, declare it as an associative PL/SQL array:

    OracleParameter param1 = new OracleParameter(); 
    param1.OracleDbType = OracleDbType.Int32; 
    param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray; 
    

    Then assign some values:

    param1 = new int[] { 3857, 3858, 3863, 3285 }; 
    

    And your query needs a cast:

    SELECT * FROM tablename a 
    where a.flokkurid in (TABLE(CAST(:manyNumbers AS number_table)))
    order by sjodategund, rodun 
    

提交回复
热议问题