PL/SQL’de parametre olarak string, belirtilen ayırac ile bölen fonksiyon. Eğer hiç ayırac kullanılmamışsa parametre olarak geçilen değer döner. Ayıraç birden fazla karakterden oluşabilir.
[sql] create or replace function str2array(pStr in varchar2, pDelim in varchar2 ) return dbms_utility.uncl_array is Result dbms_utility.uncl_array; i number; j number; lastpos number; iCount number; bFound boolean; begin i:=1; lastpos:=1; iCount:=1; while i<=length(pStr) loop bFound:=false; if substr(pStr,i,1)=substr(pDelim,1,1) then bFound:=true; for j in 1..length(pDelim) loop if substr(pStr,i+j,1)<>substr(pDelim,j+1,1)then bFound:=false; end if; end loop; if bFound then Result(iCount):=substr(pStr,lastpos,i-lastpos); iCount:=iCount+1; i:=i+length(pDelim); lastpos:=i; end if; end if; i:=i+1; end loop; if substr(pStr,lastpos,length(pStr)-lastpos+1)<>pDelim then Result(iCount):=substr(pStr,lastpos,length(pStr)-lastpos+1); end if; return(Result); end; [/sql]
Örnek kullanım :
[sql]
declare
arr dbms_utility.uncl_array;
i number;
begin
arr:= str2array('abc,d,ef',',');
for i in 1..arr.count
loop
dbms_output.put_line( arr(i) );
end loop;
end;
[/sql]