We have to load a number of huge tables using Load From cursor. The query formed for the same is a dynamic query as the column names are to be specified. we do the same using the below code in a procedure

For Mcnt As Mcur Cursor For 
  Select Di_tablename From file_mapping  Order By Id      

   For Mcnt1 As Mcur1 Cursor For Select Column_name  From Sysibm.Columns  Where Table_name=di_tablename 
       Set v_colquery = v_colquery || Column_name || ',' ;   
   End For;           

   Set v_colquery = Substr(v_colquery, 1, Length(v_colquery)-1);

 set v_sql ='LOAD FROM (SELECT '|| v_colquery || ' FROM ' || Di_tablename  || ' ) OF CURSOR INSERT INTO ' || Di_tablename || '_LOG  ( ' || v_colquery || ') NONRECOVERABLE';
call admin_cmd(v_sql);   

 END for;

The first round in loop executes just fine. But when it comes to the second it gives the below error.

The cursor specified in a FETCH statement or CLOSE statement is not open or a cursor variable in a cursor scalar function reference is not open.. SQLCODE=-501, SQLSTATE=24501, DRIVER=4.18.60

All the cursors are implicit cursors(do correct me if i am wrong). Unclear as to which cursor is being referenced and what exactly the issue is.

  • 1
    Also if i comment the Call to ADMIN_CMD it runs without any issue.
    – rrrohanb
    Dec 25, 2015 at 5:02
  • 1
    COMMIT closes the cursor. You don't need that commit anyway, because the LOAD utility is not under transaction control.
    – mustaccio
    Dec 25, 2015 at 15:33
  • Thanks it worked!! Any issues if I use cursor with hold? There are other statements that I will need to call in the same loop of this works fine..
    – rrrohanb
    Dec 25, 2015 at 20:36

1 Answer 1


It was because of Commit while using Cursor.

Adding WITH HOLD to the cursor definition resolved the Issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.