Sql 如果没有这样的方法,那么我不明白你想表达的意思。为什么“不超过4个值”相关?仅仅因为最多有4个值,而不是200个值,它如何使它“不那么复杂”?(撇开您自己的示例数据有5个值的列表这一事实不谈!)我想我解释错了。我要寻找的只是列值是否包含一个字符串。“逗号分

Sql 如果没有这样的方法,那么我不明白你想表达的意思。为什么“不超过4个值”相关?仅仅因为最多有4个值,而不是200个值,它如何使它“不那么复杂”?(撇开您自己的示例数据有5个值的列表这一事实不谈!)我想我解释错了。我要寻找的只是列值是否包含一个字符串。“逗号分,sql,oracle,Sql,Oracle,如果没有这样的方法,那么我不明白你想表达的意思。为什么“不超过4个值”相关?仅仅因为最多有4个值,而不是200个值,它如何使它“不那么复杂”?(撇开您自己的示例数据有5个值的列表这一事实不谈!)我想我解释错了。我要寻找的只是列值是否包含一个字符串。“逗号分隔的列不会超过4个,而值最多为2个。这并不像您想象的那么复杂。”没关系。在单个列中有任何逗号分隔的值这一事实违反了关系数据设计的第一条规则-第一范式。使数据模型正确-将所有表设计为第三范式-匹配问题就变得无关紧要了。@Chatra-您标记为“正


如果没有这样的方法,那么我不明白你想表达的意思。为什么“不超过4个值”相关?仅仅因为最多有4个值,而不是200个值,它如何使它“不那么复杂”?(撇开您自己的示例数据有5个值的列表这一事实不谈!)我想我解释错了。我要寻找的只是列值是否包含一个字符串。“逗号分隔的列不会超过4个,而值最多为2个。这并不像您想象的那么复杂。”没关系。在单个列中有任何逗号分隔的值这一事实违反了关系数据设计的第一条规则-第一范式。使数据模型正确-将所有表设计为第三范式-匹配问题就变得无关紧要了。@Chatra-您标记为“正确答案”的解决方案与我的解决方案的作用完全相同。那么,如果你“解释错了”,那么这个答案如何“正确”?更有可能的是,你是无知的。祝你身体健康!
Product_ID
123,234,546,789,487
SQL> set ver off
SQL>
SQL> with
  2  test (product_id) as
  3    -- your sample table
  4    (select '123,234,546,789,487' from dual union all
  5     select '111,222,333'         from dual
  6    ),
  7  test_split as
  8    -- you have to split it into rows
  9    (select product_id,
 10            regexp_substr(product_id, '[^,]+', 1, column_value) val
 11     from test
 12     cross join table(cast(multiset(select level from dual
 13                                    connect by level <= regexp_count(product_id, ',') + 1
 14                                   ) as sys.odcinumberlist))
 15    ),
 16  parameter_split as
 17    -- split input parameter into rows as well
 18    (select regexp_substr('&&par_id', '[^,]+', 1, level) val
 19     from dual
 20     connect by level <= regexp_count('&&par_id', ',') + 1
 21    )
 22  -- join split values, return the result
 23  select distinct t.product_id
 24  from test_split t join parameter_split p on p.val = t.val;
Enter value for par_id: 123,546

PRODUCT_ID
-------------------
123,234,546,789,487

SQL> undefine par_id
SQL> /
Enter value for par_id: 333

PRODUCT_ID
-------------------
111,222,333

SQL>
create type table_of_pid as table of number;
/

with
  sample_data (product_id) as (
    select '123,234,546,789,487' from dual union all
    select '333,444,555,666,888' from dual
  )
, user_input (product_list) as (
    select '234,789' from dual
  )
select *
from   sample_data
where  ( select cast(collect(pid) as table_of_pid) as input_pid
         from   user_input cross apply
                json_table('[' || product_list || ']', '$[*]'
                           columns pid number path '$')
       )
       submultiset
       ( select cast(collect(pid) as table_of_pid) as input_pid
         from   json_table('[' || product_id || ']', '$[*]'
                           columns pid number path '$')
       )
;

PRODUCT_ID         
-------------------
123,234,546,789,487
| PRODUCT_ID | | :------------------ | | 123,234,546,789,487 |