Here is an example for you.

You might want to spend some more time studying the instr() function in the SQL
manual to understand how this works.  :)


define t = 'mystr1~mystr2~mystr3'

var t varchar2(30)

begin
   select '&&t' into :t from dual;
end;
/

select
   substr(:t,1,instr(:t,'~')-1) t1
   , substr(:t,instr(:t,'~')+1, instr(:t,'~')-1) t2
   , substr(:t,instr(:t,'~',instr(:t,'~')+1)+1, instr(:t,'~')-1) t2
from dual
/

or the somewhat simpler:

select
   substr(:t,1,instr(:t,'~')-1) t1
   , substr(:t,instr(:t,'~')+1, instr(:t,'~')-1) t2
   , substr(:t,instr(:t,'~',1,2)+1, instr(:t,'~')-1) t2
from dual
/

HTH

Jared




Stefick Ronald S Contr ESC/HRIDA <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]

 01/26/2004 03:29 PM
 Please respond to ORACLE-L

       
        To:        Multiple recipients of list ORACLE-L <[EMAIL PROTECTED]>
        cc:        
        Subject:        String manipulation



I'm trying to separate a string into 3 values:
The string is:

mystr1~mystr2~mystr3

Here is the code so far:
 1  select substr(subject,1,instr(subject,'~')-1) first,

 2  substr(subject,instr(subject,'~')+1, instr(subject,'~',1,2)-1) second,

 3  substr(subject,instr(subject,'~',1,2)+1,length(subject))

 4  from test_table

 5  where test_column=1700455

The result I get is:
mystr1

mystr2~mystr3

mystr3

The result I want is:
mystr1

mystr2

Mystr3

TIA,

Scott Stefick
MILPDS OCP Oracle DBA

[EMAIL PROTECTED]

210-565-2540

Reply via email to