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!

concatenating strings and using them as dynamic variables

Kenny HamJul 8 2011 — edited Jul 12 2011
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0

I have the following code, which works, but only if the count of the subscript from suppObj.approvers =6. While yes I could add a check for the subscript
but then the code starts to become even more repetitive and the code does not scale dynamically.
BEGIN
    p_new_app_plan_no_sig1_invalid := suppObj.approvers(1).personCodeInvalid;
    p_new_app_plan_no_sig2_invalid := suppObj.approvers(2).personCodeInvalid;
    p_new_app_plan_no_sig3_invalid := suppObj.approvers(3).personCodeInvalid;
    p_new_app_plan_no_sig4_invalid := suppObj.approvers(4).personCodeInvalid;
    p_new_app_plan_no_sig5_invalid := suppObj.approvers(5).personCodeInvalid;
    p_new_app_plan_no_sig6_invalid := suppObj.approvers(6).personCodeInvalid;

END;
I would prefer to use code something similar to this, but unfortunately this throws
ERROR .... Found 'p_new_app_plan_no_sig', Expecting CASE or another statement

Using a for loop would also avoid any ORA-06533: Subscript beyond count errors if the COUNT of suppObj.approvers was not equal to 6
    FOR i IN 1..suppObj.approvers.COUNT
    LOOP
         'p_new_app_plan_no_sig'||i||'_invalid' := suppObj.approvers(i).personCodeInvalid;   
    END LOOP;


END;
Does anybody have any ideas on how this could be achieved.

many thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2011
Added on Jul 8 2011
6 comments
500 views