select * from table1 where table1.id in ('1','2','3');
select * from table1 where table1.id in(replace('1#2#3,'#',''',''')) ??
替换后查不到数据,是不是方法有问题.该如何实现替换后面#为','

解决方案 »

  1.   

    select * from table1 where table1.id in(replace('1#2#3','#','''','''')) ?? 
      

  2.   

    select ''''||replace('1#2#3','#',''',''')||'''' from dual;
      

  3.   


    SQL> select replace('1#2#3','#',''',''') from dual;REPLACE('1#2#3','#
    ------------------
    1','2','3
      

  4.   

    replace只有三个参数,一般很少用在子查询里面,用法如下SELECT REPLACE('AABBCC','A','D') Result FROM DUAL
      

  5.   


    SQL> select replace(''''||'1#2#3'||'''','#',''',''') from dual;REPLACE(''''||'1#2#3'|
    ----------------------
    '1','2','3'因此写成select * from table1 
    where table1.id in(replace(''''||'1#2#3'||'''','#',''','''));这样试试吧
      

  6.   

    楼上的,还是查不到是数据///替换函数是没有问题。就是不清楚怎么用在SQL中就查不到数据了
      

  7.   


    select * from table1 
    where table1.id in(select replace(''''||'1#2#3'||'''','#',''',''') from dual);in里面并不会产生结果集,加个select,不过我认为这种做法不合理,为何要这样用.
      

  8.   

    具体不清楚你想达到什么样的目的
    你的rreplace('1#2#3,'#',''',''') 是不是少了什么东西?但是按你的思路,可能有两种解决办法
    一、select * from table1 where replace(table1.id,'#','') in ('1','2','3')
    二、select * from table1 where table1.id in ( select replace('1#2#3','#',''',''') from dual)
      

  9.   

    现在in里面的只是个字符串,像楼上所说应该不是结果集,所以查不出来
    建议用动态SQL,然后用游标把查询结果再取出来
      

  10.   

    --如果sql语句可以代替循环,尽量不用循环,这样有利于提高性能
    select * from t_test where id =substr('1#2#3',1,instr('1#2#3','#',1,1)-1)
    union all
    select * from t_test where id =substr('1#2#3',instr('1#2#3','#',1,1)+1,instr('1#2#3','#',1,2)-instr('1#2#3','#',1,1)
      

  11.   

    动态sql。否则肯定查不出来结果,除非id和那个串一样
      

  12.   

    楼上说的有道理.我也发现是这么一回事情,但想一条SQL搞定
      

  13.   

    可以考虑用instr模拟一下in的功能,试一下
    select * from t_test where instr('#'||'1#2#3'||'#','#'||id||'#')>0
      

  14.   

    楼上说的有道理.我也发现是这么一回事情,但想一条SQL搞定
      

  15.   

    execute immediate 'select * from ttt3 where 产品 in ('||select ''''||replace('1#2#3','#',''',''')||'''' from dual||')';用動態SQL來查詢,然后用游標循環取值