create or replace function split_by_seq(c varchar2, m number)
return varchar2 as
st number := 1;
ed number;
l number;
n number := m;
begin
if c is null or m is null then
return 0;
end if;
loop
ed := instr(c, ',', st);
if (ed = 0 and n - 1 <> 0) then
return 'Input errors!';
end if;
n := n - 1;
if n = 0 then
exit;
else
st := ed + 1;
end if;
end loop;
if ed = 0 then
return substr(c, st);
end if;
l := ed - st;
return substr(c, st, l);
return 0;
end;
-------------------------------------------------------------------------------------------------------------
SQL> select split_by_seq('123,456,789,987,654,321,012,120',4) from dual;
SPLIT_BY_SEQ('123,456,789,987,
--------------------------------------------------------------------------------
987
SQL>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24825020/viewspace-695831/ ,如需转载,请注明出处,否则将追究法律责任。