简体   繁体   English

传递int的参数化查询列表返回错误ora-01722

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

Using the oledb provider. 使用oledb提供程序。 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. 我获取一个int数组并将其发送到一个方法,该方法在数组值之间添加逗号分隔符,并返回一个字符串。 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. 如果我有一个值可以通过,这可以正常工作,但是当我发送两个值时,我得到ORA-01722错误。

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. 我已经尝试查看v_$sql表以查看正在执行的内容,但它没有显示我的页面执行的查询。 I can only see things I executed via toad, even though I'm using the same login in both cases. 我只能看到我通过toad执行的操作,即使我在两种情况下都使用相同的登录。 Not sure if there are other tables that store sql data. 不确定是否有其他表存储sql数据。

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. 不幸的是,您不能将逗号分隔的字符串作为IN值。 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? 您使用哪个驱动程序连接到Oracle? Here two different odp.net solutions: http://forums.oracle.com/forums/thread.jspa?threadID=892457&tstart=810 这里有两个不同的odp.net解决方案: http ://forums.oracle.com/forums/thread.jspa?threadID = 892457&tstart = 810

edit: I see that you use the oledb provider. 编辑:我看到您使用oledb提供程序。 I guess that limits the possibilities? 我想这限制了可能性? (I've never used that provider so I don't know). (我从未使用过该提供商,所以我不知道)。 Maybe it is time to switch? 也许是时候换了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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