Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PLEASE SAVE ME!!!
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.');
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 */
/* 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;
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*
![]() |
![]() |