表中一个字段 是  1,2,3,4,5,这样的,查询条件为 1,4,5, 或者 1,2,5,都把该条记录查出来 请问怎么查询

解决方案 »

  1.   


    select * from table where col in (1,4,5) or col in (1,2,5);
      

  2.   

    select * from table1 where col=some(传进来的字符串);
      

  3.   

    不确定具体值,那只有动态SQL了
      

  4.   

    创建判断函数
    create or replace function is_have(P_col varchar2, P_condition varchar2)
      /*p_col标识对应的数据列;P_condition标识条件字符串*/
      return number is
      v_flag number := 0;
    begin
      for x in (select regexp_substr(P_condition, '[^,]+', 1, rownum) as col
                  from dual
                connect by rownum <=
                           length(regexp_replace(P_condition, '[^,]', null))) loop
        if instr(P_col, x.col) > 0 then
          v_flag := 1;
        end if;
      end loop;
      return v_flag;
    end;
    测试语句
    select * from (select '1,2,3,4,5' as col from dual) where 1=is_have(col,'1,3');