简体   繁体   中英

Passing parameterized query list of int's returns error ora-01722

Using the oledb provider. Query is something like this:

SELECT appid 
  FROM table 
 WHERE response_id IN (?)

I take an int array and send it to a method that adds a comma delimiter between the array values, and returns a string. This string is then sent as the parameter.

This works fine if I have one value to pass through, but when I send two values I get the ORA-01722 error.

I've tried looking at the v_$sql table to see what's being executed, but it's not showing queries executed by my page. I can only see things I executed via toad, even though I'm using the same login in both cases. Not sure if there are other tables that store sql data.

The string builder is below.

public string intArrayToString(int[] array)
{
    if (array != null)
    {
        string delimiter = ",";

        if (array.Length > 0)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(array[0]);
            for (int i = 1; i < array.Length; i++)
            {
                builder.Append(delimiter);
                builder.Append(array[i]);
            }                    
            return builder.ToString();
        }
        else
        {
            return string.Empty;
        }
    }
    else
    {
        return null;
    }
}

You cannot just put a comma-separated string as the IN value unfortunately. What you can do is automatically generating a bind variable for each of the array elements and binding each value, like so:

select appid from table where response_id in (:id1, :id2, :id3)

Which driver to you use to connect to Oracle? Here two different odp.net solutions: http://forums.oracle.com/forums/thread.jspa?threadID=892457&tstart=810

edit: I see that you use the oledb provider. I guess that limits the possibilities? (I've never used that provider so I don't know). Maybe it is time to switch?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM