# Posted By

ceduard0 on 07/16/13

# Statistics

Viewed 633 times
Favorited by 0 user(s)

# Find token into list of values

/ Published in: 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

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

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

Copy this code and paste it in your HTML
`CREATE OR REPLACEFUNCTION 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;/`