Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL and parsing a variable for whitespace

Re: PL/SQL and parsing a variable for whitespace

From: <mihasan_at_odin.fli.sh.bosch.de>
Date: 1997/10/21
Message-ID: <MIHASAN.97Oct21090107@odin.fli.sh.bosch.de>#1/1

Hi,

for parsing problems I wrote a function GetToken() that works like strtok() in the standard C library. You use it like that:

l_pos NUMBER;
l_separators VARCHAR2(2) := ' ,';

LOOP    l_token := GetToken(l_string, l_pos, l_separators);    IF l_token IS NULL THEN

      EXIT;
   END IF; END LOOP; Hope that helps. Here's the function:


   FUNCTION GetToken(p_string VARCHAR2, p_pos IN OUT NUMBER, p_separators VARCHAR2)    RETURN VARCHAR2
   IS

      l_akt_char      VARCHAR2(1);
      l_len           NUMBER;
      l_result_string VARCHAR2(255) := NULL;
      l_result_len    NUMBER := 0;

   BEGIN    

      IF p_string IS NULL THEN
         RETURN NULL;
      END IF;

      l_len := LENGTH(p_string) - p_pos;
      IF l_len < 0 THEN
         RETURN NULL;
      END IF;


-- Skip separators at beginning of string
LOOP IF p_pos > length(p_string) THEN return NULL; END IF; l_akt_char := SUBSTR(p_string, p_pos, 1); IF INSTR(p_separators, l_akt_char) = 0 THEN EXIT; ELSE p_pos := p_pos + 1; END IF; END LOOP;
-- Find Token
LOOP IF p_pos > length(p_string) THEN RETURN l_result_string; END IF; l_akt_char := SUBSTR(p_string, p_pos, 1); p_pos := p_pos + 1; IF INSTR(p_separators, l_akt_char) = 0 THEN l_result_string := l_result_string || l_akt_char; ELSE RETURN l_result_string; END IF; END LOOP; return NULL;

   END GetToken;
---
Received on Tue Oct 21 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US