Return to Snippet

Revision: 64226
at July 16, 2013 09:05 by ceduard0


Updated Code
create or replace
function fsbFindToken(sbValues    in VARCHAR2, 
                      sbToken     in VARCHAR2,
                      sbSeparator in VARCHAR2)
return VARCHAR2
/*
 *
 * Function    : fsbFindToken.sql
 * Autor       : ceduard0
 * Fecha       : 16/02/2011
**/
is
 sbLocated VARCHAR2(1) := 'N';
 sbListOfValues VARCHAR2(2000);
 nuLength  NUMBER;
 sbValue     VARCHAR2(2000);
begin
  sbListOfValues := trim(sbValues);
  nuLength       := Length(sbListOfValues);
		
  if (nuLength = length(REPLACE(sbListOfValues, sbSeparator))) then
       if (sbToken = sbListOfValues) then
         sbLocated := 'Y';
       end if;--if (sbToken = sbListOfValues) then
     else
        --Get data from list of value
        for i in 1..length(sbListOfValues) + 1 loop

           if (trim(substr(sbListOfValues, i, 1)) <> trim(sbSeparator)) then
               sbValue := sbValue || substr(sbListOfValues, i, 1);
           else
              -- tbcausal(i).nuCausa:=to_number(sbValue);
               if (sbToken = sbValue) then
                  sbLocated := 'Y';
                  exit;
               end if;--if (sbToken = sbValue) then
               sbValue := null;
           end if;--if (trim(substr(sbListOfValues, i, 1)) <> trim(sbSeparator)) then
       end loop;--for i in 1..length(sbValues) + 1 loop
  end if;--if (nuLength = length(REPLACE(sbListOfValues, sbSeparator))) then

  return sbLocated;
end fsbFindToken;
/

Revision: 64225
at July 16, 2013 09:04 by ceduard0


Initial Code
create or replace
function fsbFindToken(sbValues    in VARCHAR2, 
                      sbToken     in VARCHAR2,
                      sbSeparator in VARCHAR2)
return VARCHAR2
/*
 *
 * Function    : fsbFindToken.sql
 * Autor       : ceduard0
 * Fecha       : 16/02/2011
**/
is
 sbLocated VARCHAR2(1) := 'N';
 sbListOfValues VARCHAR2(2000);
 nuLength  NUMBER;
 sbValue     VARCHAR2(2000);
begin
  sbListOfValues := trim(sbValues);
  nuLength       := Length(sbListOfValues);
		
  if (nuLength = length(REPLACE(sbListOfValues, sbSeparator))) then
       if (sbToken = sbListOfValues) then
         sbLocated := 'Y';
       end if;--if (sbToken = sbListOfValues) then
     else
        --Se obtienen los datos parametrizados
        for i in 1..length(sbListOfValues) + 1 loop

           if (trim(substr(sbListOfValues, i, 1)) <> trim(sbSeparator)) then
               sbValue := sbValue || substr(sbListOfValues, i, 1);
           else
              -- tbcausal(i).nuCausa:=to_number(sbValue);
               if (sbToken = sbValue) then
                  sbLocated := 'Y';
                  exit;
               end if;--if (sbToken = sbValue) then
               sbValue := null;
           end if;--if (trim(substr(sbListOfValues, i, 1)) <> trim(sbSeparator)) then
       end loop;--for i in 1..length(sbValues) + 1 loop
  end if;--if (nuLength = length(REPLACE(sbListOfValues, sbSeparator))) then

  return sbLocated;
end fsbFindToken;
/

Initial URL

                                

Initial Description
Find a key from a list of values​​.
parameters:
sbValues​​: List of Values 'A;B;C;D'
sbToken: Key 'B'
sbSeparator: ',' or any defined sbValues

Example:
select FSBFINDTOKEN('A;B;C;D','B',';') 
  from DUAL;

-------------------
Y

Initial Title
Find token into list of values

Initial Tags
function, find

Initial Language
PL/SQL