Find token into list of values

Submitted by:Tim Kelly

Date added:30 October, 2013

Category:PL SQL

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

Tags: separator , parameter

Code Snippet:

    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;
/
 
 

Comments