[ Oracle string cut ]
return varchar2
is
substrTarget varchar2(200);
retString varchar2(200);
lenstrTarget number;
countPosition number default 1;
countChar number default 1;
countDelim number default 0;
loopExit varchar2(5) default 'false';
begin
substrTarget := strTarget;
lenstrTarget := length(strTarget);
while (countChar <= lenstrTarget) loop
if (substr(strTarget, countChar, 1) = delim) then
countDelim := countDelim + 1;
end if;
countChar := countChar + 1;
end loop;
while (countPosition <= findPosition) loop
if (countDelim < findPosition - 1) then
retString := 'N/A';
loopExit := 'true';
elsif (instr(substrTarget, delim) > 0) then
retString := substr(substrTarget, 1, instr(substrTarget, delim) - 1);
substrTarget := substr(substrTarget, instr(substrTarget, delim) + 1, length(substrTarget) - instr(substrTarget, delim));
else
retString := substrTarget;
loopExit := 'true';
end if;
countPosition := countPosition + 1;
exit when (loopExit = 'true');
end loop;
return(retString);
end strcut;
/
No comments:
Post a Comment