split函数                                        

这两天工作遇到一个小小的难题,后来用pl/sql写了一个split函数很好解决了这个问题。

要判断一个号码是否是在一个以逗号分隔的号码串的扩展,如:

判断12345111是否是11111,1234511,55555这些号码中其中一个号码的扩展,12345111应该是1234511的扩展。

参考信息:http://builder.com.com/5100-6388_14-5259821.html

对这个多了一个改进:

用一个包封装split函数:

create or replace package pk_Base is

    type t_split_tbl is table of varchar2(32767);

   function split
   (
       p_list varchar2,
       p_del varchar2 := ','
   ) return t_split_tbl pipelined;
end pk_Base;

create or replace package body pk_Base is
    function split
    (
        p_list varchar2,
        p_del varchar2 := ','
    ) return t_split_tbl pipelined
    is
        l_idx    pls_integer;
        l_list    varchar2(32767) := p_list;
        l_value    varchar2(32767);
    begin
        loop
            l_idx := instr(l_list,p_del);
            if l_idx > 0 then
                pipe row(substr(l_list,1,l_idx-1));
                l_list := substr(l_list,l_idx+length(p_del));
            else
                pipe row(l_list);
                exit;
            end if;
        end loop;
        return;
    end;
end pk_Base;

然后SQL语句中这样用:

select t.fmobile,sum(t.ffeecode) ffeecode
from fee_history t,topic_service a,table(pk_base.split('1189109121,1184444567,1185112',',') ) b
where t.ftopid = a.ftopid(+) and t.fsrvcode = a.fsrvcode(+)
and t.ffeedate >= to_date('2005-07-01','YYYY-MM-DD')
and t.ffeedate < to_date('2005-07-30','YYYY-MM-DD')+1
and t.fmobile like '0799%'
and a.fisp like b.column_value||'%'
group by t.fmobile

posted on 2006-06-20 13:11  Yang-S  阅读(989)  评论(0)    收藏  举报