Home > Ask the Oracle Experts > Questions & Answers > Parsing a delimited string
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Parsing a delimited string

Brian Peasland EXPERT RESPONSE FROM: Brian Peasland

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 11 September 2002
How can I parse a delimited string in Oracle?

>
EXPERT RESPONSE

To parse a delimited string, you will want to make use of the INSTR function to search for the components of your string. The following code example (in PL/SQL) assumes that the first character of the string is the delimiter. You can see how I search through the string and output the components of that string, minus the delimiter character.

DECLARE
   myString  VARCHAR2(255):='|this|is|a|string|';
   strLength NUMBER;
   counter   NUMBER;
   delimiter CHAR;
   spot      NUMBER;
BEGIN 
   -- Get length of string
   strLength:=LENGTH(myString);
   -- Get delimiter character
   delimiter:=SUBSTR(myString,1,1);
   DBMS_OUTPUT.PUT_LINE('The delimiter is:
'||delimiter); 
   -- start with second character of the string
   counter:=2;
   LOOP
      -- Find the next delimiter location
      spot:=INSTR(myString,delimiter,counter); 
      -- Print out the component of the string
     
DBMS_OUTPUT.PUT_LINE(SUBSTR(myString,counter,spot-counter));
      -- Move to next location after the delimiter
      counter:=spot+1;
      -- Continue until entire string has been
processed 
      EXIT WHEN counter >= strLength;
   END LOOP;
END;
/

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts