Page 1 of 1

Array selects

Posted: Wed 12 Apr 2006 13:54
by AL
Hi, exploring array bind feature of OraDirect, I noticed that all examples are about inserts/updates/deletes... And nothing about selects.

But the problem is simple. I need to pass array of IDs (guids in my case, raw(16)) to retrieve several rows.

So select looks like this:

select * from objects where guid=:guid

I define "guid" parameter and pass one value. So this select works just fine. But the question is what happens if I put an array of elements in the value of this parameter?

Will this works like:

select * from objects where guid in (x1, x2, x3...xN)

where x1...xN are values from my array?

Any help would be really appreciated...

Posted: Thu 13 Apr 2006 09:54
by Alexey
The multiple inserts/updates/deletes intend execution of the same command several times with different parameters. Selects in this case would not have any sense.

ok

Posted: Thu 13 Apr 2006 12:24
by AL
Ok, the question then is how to bind array to variable list in IN operator.

Any suggestions?

Posted: Fri 14 Apr 2006 16:54
by AL
found a solution...

select * from table where id in (select * from table(:param))

where param is plsql type "NumTable" (defined as table of number).

OracleParameter param = cmd.Parameters.Add("param", OracleDbType.Array);

OracleArray values = new OracleArray("NumTable", connection);

values.Add(value1);
values.Add(value2);
...
values.Add(valueX);

param.Value = values;

OracleDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
.. read your data here...
}