Find token into list of values


/ Published in: PL/SQL
Save to your folder(s)

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
  1. FUNCTION fsbFindToken(sbValues IN VARCHAR2,
  2. sbToken IN VARCHAR2,
  3. sbSeparator IN VARCHAR2)
  4. /*
  5.  *
  6.  * Function : fsbFindToken.sql
  7.  * Autor : ceduard0
  8.  * Fecha : 16/02/2011
  9. **/
  10. sbLocated VARCHAR2(1) := 'N';
  11. sbListOfValues VARCHAR2(2000);
  12. nuLength NUMBER;
  13. sbValue VARCHAR2(2000);
  14. sbListOfValues := TRIM(sbValues);
  15. nuLength := LENGTH(sbListOfValues);
  16.  
  17. IF (nuLength = LENGTH(REPLACE(sbListOfValues, sbSeparator))) THEN
  18. IF (sbToken = sbListOfValues) THEN
  19. sbLocated := 'Y';
  20. END IF;--if (sbToken = sbListOfValues) then
  21. --Get data from list of value
  22. FOR i IN 1..LENGTH(sbListOfValues) + 1 LOOP
  23.  
  24. IF (TRIM(SUBSTR(sbListOfValues, i, 1)) <> TRIM(sbSeparator)) THEN
  25. sbValue := sbValue || SUBSTR(sbListOfValues, i, 1);
  26. -- tbcausal(i).nuCausa:=to_number(sbValue);
  27. IF (sbToken = sbValue) THEN
  28. sbLocated := 'Y';
  29. END IF;--if (sbToken = sbValue) then
  30. sbValue := NULL;
  31. END IF;--if (trim(substr(sbListOfValues, i, 1)) <> trim(sbSeparator)) then
  32. END LOOP;--for i in 1..length(sbValues) + 1 loop
  33. END IF;--if (nuLength = length(REPLACE(sbListOfValues, sbSeparator))) then
  34.  
  35. RETURN sbLocated;
  36. END fsbFindToken;
  37. /

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.