如题,有固定的id串格式如下
123;321;345;567 中间用分号隔开存在一个字段中,现在要将这个串写个oracle函数,解析为如下格式
'123','456','789' 便于 我用in 函数 in ('123','456',.....)
高手指教,这个函数咋写啊。。谢谢了

解决方案 »

  1.   

    嗯 程序中好弄,现在需求在用oracle函数
      

  2.   

    substr(字段, 1, 3)  用substr函数取字符串位数吧。
      

  3.   


    select chr(39)||replace('123;321;345;567',';',''',''')||chr(39) c1
    from dual            c1
    --------------------------------
    1 '123','321','345','567'
      

  4.   


    create or replace function fun_test(i_str in varchar2) return varchar2 as
    begin
      return '''' || replace(i_str, ';', ''',''') || '''';
    end;
    select fun_test('123;321;345;567') from dual;
        FUN_TEST('123;321;345;567')
    1 '123','321','345','567'
      

  5.   

    select * from TB where id in(
    select  regexp_substr('123;321;345;567', '[^;]+', 1, rownum) from dual
    connect by rownum <= length(regexp_replace('123;321;345;567', '[^;]'))+1)