title: I want to run stored procedure in a loop
body: <p>I want to run sp in a loop .
  I am using db2.
  For ex if there are 10 rows in my table and 8 rows contain status as approved ,I want those 8 rows to be executed 1 by 1 through my sp .</p>
  
  <p>I have used this method </p>
  
  <pre><code>declare @v_count INT;
  declare @row_count INT;
  
  declare @v_actorCNUM      CHAR(10); 
  declare @v_sessID      CHAR(32);
  declare @v_taskID      SMALLINT;
  declare @v_dest_citrusSCID   INTEGER;  
  declare @v_src_citrusSCID  INTEGER;
  declare @v_CtrCnum         CHAR(10);
  declare @v_dest_security_grp_nm  varchar(100);  
  declare @v_src_security_grp_nm  varchar(100);
  
  SET @v_count=1;
   DECLARE GLOBAL TEMPORARY TABLE csc_trfr
  (   
    Row_id INT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
   CNTRCTR_CNUM CHAR(10) NOT NULL ,
                DEST_CSC_NM CHAR(30) ,
                SRC_CSC_NM CHAR(30) ,
                DEST_GRP_NM VARCHAR(100) ,
                SRC_GRP_NM VARCHAR(100) ,
                USR_LST_UPDT_ID CHAR(10) 
    ) WITH REPLACE ON COMMIT PRESERVE ROWS NOT lOGGED;
   insert into       session.csc_trfr                                                 (cntrctr_cnum,dest_csc_nm,src_csc_nm,dest_grp_nm,src_grp_nm,usr_lst_updt_id)
    select    cntrctr_cnum,dest_csc_nm,source_csc_nm,dest_grp_nm,src_grp_nm,usr_lst_updt_id from citrus.cntrctr_csc_trfr where trfr_status='Approved';
  
      select count(*) into @row_count from citrus.cntrctr_csc_trfr where  trfr_status='Approved';
  
  while @v_count&lt;=@row_count
  
    BEGIN
  
  
   SET @v_actorCNUM=select usr_lst_updt_id from session.csc_trfr order by    row_id offset @v_count rows fetch next 1 rows only;
   SET @v_taskID=166;
    set @v_dest_citrusSCID =select citrus_suprt_id from citrus.citrus_suprt_cntr where citrus_suprt_nm=(select DEST_CSC_NM from session.csc_trfr order by row_id offset @v_count rows fetch next 1 rows only );
  set @v_src_citrusSCID=select citrus_suprt_id from citrus.citrus_suprt_cntr where citrus_suprt_nm=(select SRC_CSC_NM from session.csc_trfr order by row_id offset @v_count rows fetch next 1 rows only );
   set @v_CtrCnum=select cntrctr_cnum from session.csc_trfr order by row_id offset @v_count rows fetch next 1 rows only;
   set @v_dest_security_grp_nm =select  DEST_GRP_NM from session.csc_trfr order by row_id offset @v_count rows fetch next 1 rows only;
  set @v_src_security_grp_nm=select  DEST_GRP_NM from session.csc_trfr order by row_id offset @v_count rows fetch next 1 rows only;
   call citrus.BAC020_cntrctrCSCTrfr(@v_actorCNUM,'',@v_taskID,@v_dest_citrusSCID,@v_src_citrusSCID,@v_CtrCnum,@v_dest_security_grp_nm,@v_src_security_grp_nm,?,?,?);
    @v_count=@v_count+1;
   end
  </code></pre>
  
  <p>I have name script as test.sql and executing script like :
  db2 -tvf test.sql
  but I am getting sql error.
  DB21034E  The command was processed as an SQL statement because it was not a
  valid Command Line Processor command.  During SQL processing it returned:
  SQL0104N  An unexpected token "declare @v_actorCNUM      CHAR" was found
  following "BEGIN-OF-STATEMENT".  Expected tokens may include:  "".
  LINE NUMBER=1.  SQLSTATE=42601 </p>
  
  <p>error is same for all variables.</p>
  
  <p>My code is count the rows in cntctr_csc_trfr table where transfer status is approved .and then I am putting those rows in temp table .For each row in temp table I want to run stored procedure.</p>