Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Assign values to variables in while loop

managed BEANOct 15 2015 — edited Oct 15 2015

Hello experts,

I am creating a package with procedures/functions.

One of my issues was to create the below code:

DECLARE

    comma_pos      PLS_INTEGER;

    p_list         VARCHAR2 (500) := '10000000C445652B1057C738561F6862A891B80C,10000000CC6BA1CE146331BCE33637106C31F049,10000000FE7FC766360C28BE5AD1BE266A83C173';

    remaining_txt  VARCHAR2 (500) := p_list;

    token          VARCHAR2 (500);

    Part1          VARCHAR2 (500);

    Part2          VARCHAR2 (500);

    Part3          VARCHAR2 (500);

       

BEGIN

    WHILE  remaining_txt  IS NOT NULL

    LOOP

        comma_pos := INSTR ( remaining_txt || ',' , ','  );

        token := SUBSTR ( remaining_txt , 1 , comma_pos - 1 );

        dbms_output.put_line (token );

        remaining_txt := SUBSTR ( remaining_txt, comma_pos + 1 )

    END LOOP;

END;

/

Now, i would like to assign each of the value (it´s3) that the 'token' has which showns in output.

It should be assigned in the end the following:

Part1: 10000000C445652B1057C738561F6862A891B80C

Part2: 10000000CC6BA1CE146331BCE33637106C31F049

Part3: 10000000FE7FC766360C28BE5AD1BE266A83C173

This could be dinamicaly to be scalabe (imagine that tomorrow will be 4 parts, for example) if necessary, not required.

Looking forward for your valuable answers,

Regards,

Carlos

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 12 2015
Added on Oct 15 2015
11 comments
2,501 views