0

I am working in C#.Net and Oracle. i am passing a string to a query. i had used this code for concating all the item id's

List<string> listRetID = new List<string>();
                foreach (DataRow row in dtNew.Rows)
                {
                    listRetID.Add(row[3].ToString());
                }

This concatination goes above 10,000. so i am getting the error message like this..

ORA-01795: maximum number of expressions in a list is 1000

How to fix this..

RobinHood
  • 2,367
  • 11
  • 46
  • 73

4 Answers4

4

The documentation states:

A comma-delimited list of expressions can contain no more than 1000 expressions. A comma-delimited list of sets of expressions can contain any number of sets, but each set can contain no more than 1000 expressions.

Presumably you're using this string as the contents of in IN (...) restriction, in which case there isn't really anything you can do - this just won't work. A common way to work around this is to generate a dummy table as a subquery or common table expression (CTE) and joining to that, but I'm not sure how you'd translate your List - possibly similar to whatever you're doing with your IN clause. You'd want to end up with your query looking something like:

with tmp_tab as (
    select <val1 from list> as val from dual
    union all select <val2 from list from dual
    union all select <val3 from list from dual
    ...
)
select <something>
from <your table> yt
join tmp_tab tt on yt.<field> = tt.val

But that requires generating the entire (huge) query including the CTE each time you run it, and there's no opportunity to use bind variables.

You might find something like this approach more palatable.

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • this is pretty clear. You have to do that in multiple queries with ID batches of max 1000 id's and than stick the results together one way or another. – Hugo Jul 19 '12 at 12:53
1

You can have 10 lists of 1000 items instead of 1 list of 10000 items.

WHERE some_column IN (1,2,...,1000)
   OR some_column IN (1001,1002,...2000) -- etc.
jva
  • 2,797
  • 1
  • 26
  • 41
  • how can i take that 1000 id's out from the list of 10000 id's..the values are not hardcoded. all are dynamic. – RobinHood Jul 19 '12 at 13:06
  • Sorry, I can't give you C# code :( Probably you can use a list of List and switch to new element after 1000 values. – jva Jul 19 '12 at 13:09
0

Not a C# guy but I would just split the list listRetID in multiple lists or create a list of lists

Then loop through that list of lists and perform the query on each element of the list.

Community
  • 1
  • 1
Hugo
  • 12,334
  • 6
  • 30
  • 36
0

What is the intent of your query?

It looks like you are selecting rows that have some column equal to the 3rd column of one of the records of some query.

The correct way of doing this is either an SQL join or a subquery. There is absolutely no need to bring this into C# code. For example, using a subquery you can write something like this:

SELECT *
FROM atable
WHERE afield IN (
    SELECT field3
    FROM someothertable)
Olaf
  • 6,249
  • 1
  • 19
  • 37