Home » SQL & PL/SQL » SQL & PL/SQL » Parse a String
Parse a String [message #7253] Fri, 30 May 2003 11:57 Go to next message
MM
Messages: 27
Registered: July 2002
Junior Member
I have a problem in capturing values from string. I will explain as easy i can

OM0106;TM0345;SM1234;HM0989;

this is the string, when i am parsing i will be needing the first value that is OM0106 and second value TM0345 and so on till there are no values in the string, i dont need the semicolon. I am tring to use SUBSTR in combination INSTR functions and could go only one level of capturing the values, i am stuck when i am trying to retrieve the next value.

Your help is appreciated.

Thanks,
MM
Re: Parse a String [message #7256 is a reply to message #7253] Fri, 30 May 2003 13:09 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Here's an anonymous block that shows how the parsing might be done:

sql>declare
  2    v_string  long := 'OM0106;TM0345;SM1234;HM0989;';
  3    v_pos     pls_integer;
  4  begin
  5    loop
  6      v_pos := instr(v_string, ';');
  7      exit when (nvl(v_pos, 0) = 0);
  8      dbms_output.put_line(trim(substr(v_string, 1, v_pos - 1)));
  9      v_string := substr(v_string, v_pos + 1);
 10    end loop;
 11  end;  
 12  /
<b>OM0106
TM0345
SM1234
HM0989</b>
 
PL/SQL procedure successfully completed.
Re: Parse a String [message #7258 is a reply to message #7256] Fri, 30 May 2003 13:56 Go to previous message
MM
Messages: 27
Registered: July 2002
Junior Member
Todd

Thanks a lot in helping me out

MM
Previous Topic: Java returns same timestamp
Next Topic: Argument string too long
Goto Forum:
  


Current Time: Thu Mar 28 06:19:43 CDT 2024