Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: String manipulation

RE: String manipulation

From: SRIDHARAN, SAN (SBCSI) <ss4569_at_sbc.com>
Date: Mon, 26 Jan 2004 16:34:25 -0800
Message-ID: <F001.005DE28E.20040126163425@fatcity.com>




Message



Substr(''mystr1~mystr2~mystr3', 1, 20) => 1 is the position and 20 the length (not the position).
The "substring" functions return a portion of string, beginning at character position, substring_length characters long.

SELECT substr('mystr1~mystr2~mystr3',1,instr('mystr1~mystr2~mystr3','~')-1) W_First,
               substr('mystr1~mystr2~mystr3',instr('mystr1~mystr2~mystr3','~')+1,
                         (INSTR('mystr1~mystr2~mystr3', '~', 1,2)-1)-(INSTR('mystr1~mystr2~mystr3','~',1,1)) ) W_SECOND,
               substr('mystr1~mystr2~mystr3',instr('mystr1~mystr2~mystr3','~',1,2)+1,length('mystr1~mystr2~mystr3')) W_THIRD  

  FROM dual;

-----Original Message-----
From: Stefick Ronald S Contr ESC/HRIDA [mailto:Ronald.Stefick@RANDOLPH.AF.MIL]
Sent: Monday, January 26, 2004 3:29 PM
To: Multiple recipients of list ORACLE-L
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
scott.stefick@randolph.af.mil
210-565-2540

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: SRIDHARAN, SAN (SBCSI)
  INET: ss4569_at_sbc.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Jan 26 2004 - 18:34:25 CST

Original text of this message

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