title: Tablename as variable in DB2 procedure in for loop
body: <p>I would like to transform the following script from static sql statement for <code>FOR</code> loop in DB2 to a dynamic one. concretly taking the tablename from the procedure parameters and use it in the SQL statement in the <code>FOR DO</code> loop. </p>
  
  <p>The starting point is this script:</p>
  
  <pre><code>CREATE PROCEDURE P()
  LANGUAGE SQL
  BEGIN ATOMIC
  DECLARE fullname CHAR(40);
  
  FOR v AS cur1 CURSOR FOR 
              SELECT firstnme, midinit, lastname FROM employee
  DO 
    SET fullname = v.lastname || ',' || v.firstnme 
                   ||' ' || v.midinit;
    INSERT INTO tnames VALUES (fullname);
  END FOR;
  END
  </code></pre>
  
  <p>I would like to do something like this : </p>
  
  <pre><code>CREATE PROCEDURE P(IN TABLENAME VARCHAR(128) DEFAULT 'TABLE1')
  LANGUAGE SQL
  BEGIN ATOMIC
  DECLARE fullname CHAR(40);
  
  FOR v AS cur1 CURSOR FOR 
              SELECT firstnme, midinit, lastname FROM TABLENAME 
  DO 
    SET fullname = v.lastname || ',' || v.firstnme 
                   ||' ' || v.midinit;
    INSERT INTO tnames VALUES (fullname);
  END FOR;
  END
  </code></pre>
  
  <p>Is there a way to do this ? I've tried the <code>STATEMENT</code> but I can't make it work with <code>FOR LOOP</code>. </p>