Home > Ask the Oracle Experts > Questions & Answers
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Splitting a string, part 1

Frank Kulash EXPERT RESPONSE FROM: Frank Kulash

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 07 November 2003
I simply want to pass in a string parameter to a procedure, something like this:
 01|03|07|11|99|100|231

I need to split the string in the procedure, then select from table a a value based on the values passed in from the string, and then I need to insert that value into table b. I want to do this loop for every value contained in the string ('01' first, then '03', '07', etc.).


>
EXPERT RESPONSE
I see two different jobs here. You need to:
  1. split the string to get individual values. (From now on, I'll refer to this task as "divide".)
  2. do whatever you need to do with each value. (I'll call this "conquer".)

Your ultimate goal is to conquer, and it sounds like you know how to handle that part; perhaps you already have a procedure that does it for a single value. Don't touch that procedure! For purposes of code maintenance it's best to have this logical unit contained in a separate module.

CREATE OR REPLACE  PROCEDURE  goal
(
    in_text  IN  table_a.id%TYPE
)
--      ***************
--      **  g o a l  **
--      ***************

--  goal inserts yadda yadda yadda ...
--  based on table_a blah blah blah ...

IS
BEGIN
    INSERT INTO table_b (column_2)
    SELECT  column_1
    FROM    table_a
    WHERE   id = in_text;
EXCEPTION
    WHEN  NO_DATA_FOUND
        THEN  ...
END  goal;
/

Since dividing is such a generic, useful task, you'll almost certainly want to isolate it as a separate procedure. If you're using packages, you'll want the two procedures in separate packages, since you'll probably want to give lots of people the ability to divide, but only a few people will have the power to conquer.

Continued on page 2.


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