Ask the Expert

Splitting a string, part 1

I simply want to pass in a string parameter to a procedure, something like this:

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.).

    Requires Free Membership to View

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.

    in_text  IN
--      ***************
--      **  g o a l  **
--      ***************

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

    INSERT INTO table_b (column_2)
    SELECT  column_1
    FROM    table_a
    WHERE   id = in_text;
        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.

This was first published in November 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: