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: PLEASE SAVE ME!!!

Re: PLEASE SAVE ME!!!

From: Anurag Varma <AVARMA_at_prodigy.net>
Date: Wed, 25 Aug 1999 00:47:24 -0500
Message-ID: <7pvsaa$3q1q$1@newssvr03-int.news.prodigy.com>


Here is a plsql procedure which does what you asked for below. Though to me the code doesn't look good but I couldn't find a better way to do this.

NOTE: "set serveroutput on" in sqlplus before you run it.To run it syntax is:
exec tokenizer('Your string here; with, commas: colons spaces et. al.');




CREATE OR REPLACE PROCEDURE tokenizer(in_str IN VARCHAR2)AS str_left VARCHAR2(32767);
/* Change PLS_INTEGER to NUMBER if plsql doesn't support it */ str_end PLS_INTEGER;
sp1 PLS_INTEGER; /* For space      */
sc1 PLS_INTEGER; /* For semi-colon */
st1 PLS_INTEGER; /* For stop       */
cm1 PLS_INTEGER; /* For comma      */
cn1 PLS_INTEGER; /* For colon      */

c_greatest_value CONSTANT PLS_INTEGER:=2147483647; BEGIN
/* Use this if tabs are to be treated as tabs */
  str_left := in_str;
/* Use this if tabs are to be treated as spaces */
  str_left := REPLACE(in_str,chr(9),' '); LOOP
     /* Finding first occurence of respective characters */
     sp1 := INSTR(str_left,' ',1);
     sc1 := INSTR(str_left,';',1);
     cm1 := INSTR(str_left,',',1);
     st1 := INSTR(str_left,'.',1);
     cn1 := INSTR(str_left,':',1);
     /* If the character doesn't occur set first_occurence to max value */
     IF sp1=0 THEN
         sp1 := c_greatest_value;
     END IF;
     IF sc1=0 THEN
         sc1 := c_greatest_value;
     END IF;
     IF cm1=0 THEN
         cm1 := c_greatest_value;
     END IF;
     IF st1=0 THEN
         st1 := c_greatest_value;
     END IF;
     IF cn1=0 THEN
         cn1 := c_greatest_value;
     END IF;
     str_end := LEAST(sp1,sc1,cm1,st1,cn1);
     IF str_end = c_greatest_value THEN
        IF str_left IS NOT NULL THEN
            DBMS_OUTPUT.PUT_LINE(str_left);
        END IF;
        EXIT;
     END IF;
     IF str_end = sp1 THEN
       /* We don't want to print out spaces. Spaces appear in dbms_outputif
we
          "set serveroutput on size 1000000 FORMAT WORD_WRAPPED" */
       IF (SUBSTR(str_left,1,str_end-1) != ' ') THEN
          DBMS_OUTPUT.PUT_LINE(SUBSTR(str_left,1,str_end-1));
       END IF;
       str_left := SUBSTR(str_left,str_end+1);
     ELSE
       /* We don't want to print out spaces. Spaces appear in dbms_outputif
we
          "set serveroutput on size 1000000 FORMAT WORD_WRAPPED" */
       IF (SUBSTR(str_left,1,str_end-1) != ' ') THEN
          DBMS_OUTPUT.PUT_LINE(SUBSTR(str_left,1,str_end-1));
       END IF;
       str_left := SUBSTR(str_left,str_end);
       DBMS_OUTPUT.PUT_LINE(SUBSTR(str_left,1,1));
       str_left := SUBSTR(str_left,2);
     END IF;
     IF str_left IS NULL THEN
        EXIT;
     END IF;

  END LOOP;
END tokenizer;
/


have fun
Anurag

ade victor wrote in message <0a0133f8.3ccf02e1_at_usw-ex0108-060.remarq.com>...

>GIVEN THAT THE INPUT DATA CONSISTS OF ENGLISH-LANGUAGE
>TEXT, LET US WRITE A PROCEDURE TO READ AND STORE A SINGLE
>'TOKEN',WHERE A TOKEN IS A WORD, A PERIOD,A COMMA,A
>SEMICOLON,A COLON OR AN END OF DATA INDICATION(FULL STOP).
>ASSEUME THAT A WORD IS ASEQUENCE OF CONSECUTIVE LETTERS.
>ALL OTHER CHARACTERS ARE TO BE IGNORED.
>THIS IS AN ASSIGNMENT THAT I NEED HELP WITH.
>THE OUTPUT IS SUPPOSE TO BE
>ADE
>;
>VICTOR
>:
>GONE
>.
>SIX LINES ON OUTPUT.                  (ADE VICTOR)
>
>* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network
*
>The fastest and easiest way to search and participate in Usenet - Free! > Received on Wed Aug 25 1999 - 00:47:24 CDT

Original text of this message

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