Home » SQL & PL/SQL » SQL & PL/SQL » how to tokenise a varchar or string
how to tokenise a varchar or string [message #4003] Fri, 01 November 2002 01:55 Go to next message
vvMurthy Raju
Messages: 1
Registered: November 2002
Junior Member
hi,

I am sending a vachar to the procedure.
the varchar consists of a delimiter.
can i get the two strings seperated using the delimiter.

eg: the varchar is 1;4;5
I have to seperate the values to 1 4 5
Is there any function.

Thanks & Regards
Murthy
Re: how to tokenise a varchar or string [message #4004 is a reply to message #4003] Fri, 01 November 2002 05:44 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
murthy,
May be, this is useful to u.
this is proceudre that, takes a string , seperated by some delimitors, and output is, all the seperator removed. you can use any seperator.
just convert this into a function.
SQL> get din
  1  -- dinesh this may helpyou...change it accordingly.
  2  -- usage : sp_emails('string','separator')
  3  create or replace
  4  PROCEDURE sp_emails
  5  (
  6       v_in varchar2,
  7       v_te varchar2
  8  )
  9  as
 10  a   VARCHAR2 (1);
 11  b   VARCHAR2 (30);           -- max length of a single email id..increase it as ur need
 12  i   NUMBER;
 13  str varchar2(300);           -- max value of arrays as input..increase it as ur need
 14  cnt number;
 15  BEGIN
 16  i:=1;
 17  str:=v_in||v_te;
 18  FOR mag IN 1..length(str) LOOP
 19       a:=substr(str,i,1);
 20       IF a=v_te THEN
 21               i:=i+1;
 22  --              DBMS_OUTPUT.PUT_LINE (b);       -- for debugging..remove later
 23        ELSE
 24               b:=b||' '||a;
 25               i:=i+1;
 26       END IF;
 27       END loop;
 28  dbms_output.put_line(b);   -- for debugging..remove later or create an OUT paramter
 29* END;
SQL> /

Procedure created.

SQL> begin
  2      sp_emails('1:4:5',':');
  3  end;
  4  /
1 4 5

PL/SQL procedure successfully completed.

SQL> begin
  2      sp_emails('1;4;5',';');
  3  end;
  4  /
1 4 5

PL/SQL procedure successfully completed.

SQL>  begin
  2       sp_emails('1*4*5','*');
  3   end;
  4  /
1 4 5

PL/SQL procedure successfully completed.

Previous Topic: Attention Todd Barry or Andrew
Next Topic: regarding Name-in and copy built-ins
Goto Forum:
  


Current Time: Sun Apr 28 15:50:53 CDT 2024