I wanted to convert a stored procedure to a table UDF to give the option of selecting and viewing the output in STDOUT and to have a better control. I created the function as below. But, it gives me error as "Clauses are mutually exclusive"

Code:
CREATE FUNCTION test_fn ()
  RETURNS TABLE 
  (id varchar(10),
  sql_text varchar(100),
   row_cnt integer)
  BEGIN 
    DECLARE V_DYNAMIC VARCHAR(100) ;                     
    DECLARE v_Tsql VARCHAR(2048) ;
    DECLARE v_Tid integer ;
    DECLARE SQLCODE INT DEFAULT 0;
    DECLARE v_SQLCODE INT DEFAULT 0;
    DECLARE v_exitcode integer ; 
    DECLARE v_Cnt Decimal;
    
    declare CURSOR2 cursor with return for V_DYNAMIC;
    DECLARE cursor1 CURSOR with return for 
          SELECT ID,SQLtext FROM  SQL_Table where id>=1;--
                           
    DECLARE continue HANDLER FOR NOT FOUND
    SET v_exitcode = 1;
    
    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
    set v_SQLCODE = SQLCODE;
	   
    Open cursor1;
    REPEAT
     fetch cursor1 into v_Tid, v_Tsql;    
     PREPARE V_DYNAMIC from v_Tsql; 
     	open cursor2;                                   
     	fetch cursor2 into v_Cnt;      
      	close cursor2;
      UNTIL v_exitcode = 1
    end REPEAT ;
   close cursor1;
  return values (v_Tid, v_Tsql, v_Cnt);
END