Oracle/c#: How do i use bind variables with select statements to return multiple records?

Posted by twiga on Stack Overflow See other posts from Stack Overflow or by twiga
Published on 2010-05-26T16:58:14Z Indexed on 2010/05/26 17:01 UTC
Read the original article Hit count: 235

Filed under:
|
|
|
|

I have a question regarding Oracle bind variables and select statements.

What I would like to achieve is do a select on a number different values for the primary key. I would like to pass these values via an array using bind values.

select * from tb_customers where cust_id = :1

int[] cust_id = { 11, 23, 31, 44 , 51 };

I then bind a DataReader to get the values into a table.

The problem is that the resulting table only contains a single record (for cust_id=51). Thus it seems that each statement is executed independently (as it should), but I would like the results to be available as a collective (single table).

A workaround is to create a temporary table, insert all the values of cust_id and then do a join against tb_customers. The problem with this approach is that I would require temporary tables for every different type of primary key, as I would like to use this against a number of tables (some even have combined primary keys).

Is there anything I am missing?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Oracle