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!

EXECUTE IMMEDIATE FOR (Select ....) with LOOP

2841522Jan 17 2015 — edited Jan 19 2015

Hi, can you help me?

   I need to create a cursor with table name as a variable.

Something in the following example:

DECLARE POR_ID NUMBER(10,0);

        TBL_NAME_PROV VARCHAR2(100);

        SMLPOR VARCHAR2(20);

BEGIN

TBL_NAME_PROV := 'TMP_PROV_5652_0_65';

  --FOR SMLPOR IN (EXECUTE IMMEDIATE 'SELECT TD_SITPORADCE_ID FROM ' || TBL_NAME_PROV)

   EXECUTE IMMEDIATE 'FOR SMLPOR IN (SELECT TD_SITPORADCE_ID FROM ' || TBL_NAME_PROV || ')''';

    LOOP

      POR_ID := SMLPOR.TD_SITPORADCE_ID;

      DBMS_OUTPUT.PUT_LINE('TD_SITPORADCE_ID : = ' || POR_ID);

    END LOOP;

END;

I tried a different syntax, but all did not work.

Thank you.

MV

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 16 2015
Added on Jan 17 2015
4 comments
16,244 views