Monday, July 31, 2017

▷ Oracle string cut (오라클 문자열 자르기)

[ Oracle string cut ]


create or replace function strcut(strTarget in varchar2, delim in char, findPosition in number)
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

◈ Recent Post

▷ UITest demo with TestOne (Mobile, Keypad and Drag until found tip)

[ UITest Demo Environment ] 1. UITest Solution: TestOne 2. Description 데모 설명    How to use keypad, and to drag until found.     키패드를...

◈ Popular Posts