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: Using instr in substr more than once

Re: Using instr in substr more than once

From: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Wed, 20 Feb 2002 21:08:18 +0000
Message-ID: <3C741042.4D3D@yahoo.com>


Leanne Gleitz wrote:
>
> I have some data set up in the following manner :
>
> 12345*67*8
> 9876*54
> 456
>
> Is there any way to use a simple select to pull out the data into
> three separate columns :
>
> 12345 67 8
> 9876 54
> 456
>
> I have tried the following:
>
> select substr(data,1,instr(data,'*')-1)
> ,substr(data,instr(data,'*')+1,instr(data,'*',1,2))
> from data_table
>
> but this doesn't seem to work at getting the first 2 separated out.
>
> For example the first one is returning
>
> 12345 67*8
>
> Help! Thanks in advance!

instr takes 4 params, the 3rd (?) being the n'th occurrence, so you could have:

select

  substr(col,instr(col,'*',1))
  substr(col,instr(col,'*',2))
  substr(col,instr(col,'*',3))

etc

hth
connor

-- 
==============================
Connor McDonald

http://www.oracledba.co.uk

"Some days you're the pigeon, some days you're the statue..."
Received on Wed Feb 20 2002 - 15:08:18 CST

Original text of this message

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