Sql 动态查询,参数不适用于中的何处

Sql 动态查询,参数不适用于中的何处,sql,database,oracle,oracle10g,where-in,Sql,Database,Oracle,Oracle10g,Where In,我正在oracle上处理动态查询,当我传递where in条件的字符串参数时,它就不起作用了 for x in ( SELECT DISTINCT column_id FROM table WHERE column_id in (in_column_ids) /* WHERE column_id in (15,16,17) =>works */ /*

我正在oracle上处理动态查询,当我传递where in条件的字符串参数时,它就不起作用了

for x in (
            SELECT DISTINCT column_id
            FROM table
            WHERE column_id in (in_column_ids)          
            /* WHERE column_id in (15,16,17) =>works */
            /* => in_column_ids is a varchar type which 
                  holds comma separated value */
            and column_title=in_column_title /* works */
    )
在这里,如果我将值直接保存在\u column\u id中,查询就会工作。 但是,作为参数传递的值似乎不适用于
中的
位置


有什么想法吗?

在我看来,你必须用逗号分隔变量。您的查询应如下所示:

for x in (
            SELECT DISTINCT column_id
            FROM table
            WHERE column_id in (
            SELECT DISTINCT regexp_substr(in_column_ids,'[^,]+', 1, LEVEL) FROM DUAL
            CONNECT BY regexp_substr(in_column_ids, '[^,]+', 1, LEVEL) IS NOT NULL
            )          
            /* WHERE column_id in (15,16,17) =>works */
            /* => in_column_ids is a varchar type which 
                  holds comma separated value */
            and column_title=in_column_title /* works */
    )
查看