The following procedure is stuck in a loop. All I am trying to do is read some columns from a table, load it in TEMP table and write it to a file. Can someone help me here?
{code}
drop procedure Proc_Test
CREATE PROCEDURE SVITTALAM.Proc_Test
(OUT p_Cnt VARCHAR(4),
OUT p_SQLSTATE VARCHAR(100)
)
LANGUAGE SQL
BEGIN
DECLARE V_DYNAMIC VARCHAR(100) ; -- (2)
DECLARE v_Tsql VARCHAR(100) ;
DECLARE v_Tid VARCHAR(100) ;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE v_SQLSTATE CHAR(5) DEFAULT '00000'; -- (2)
DECLARE cursor1 CURSOR with hold FOR
SELECT ID,SQLTEXT FROM test;--
DECLARE CONTINUE HANDLER FOR SQLWARNING, SQLEXCEPTION, NOT FOUND
SET p_SQLSTATE = SQLSTATE;
DECLARE GLOBAL TEMPORARY TABLE Rslt (
sql_id varchar(100),
cnt Varchar(4),
sql_state varchar(6)
)
on commit
preserve rows
not logged ;
Open cursor1;
A:
Loop
fetch cursor1 into v_Tid, v_Tsql;
insert into session.Rslt values(v_Tsql, v_Tid, '0');
commit;
call sysproc.admin_cmd('export to c:\test\test.csv of del select * from session.Rslt') ;
end loop A;
close cursor1;
drop table session.Rslt;
END
{code}
{code}
drop procedure Proc_Test
CREATE PROCEDURE SVITTALAM.Proc_Test
(OUT p_Cnt VARCHAR(4),
OUT p_SQLSTATE VARCHAR(100)
)
LANGUAGE SQL
BEGIN
DECLARE V_DYNAMIC VARCHAR(100) ; -- (2)
DECLARE v_Tsql VARCHAR(100) ;
DECLARE v_Tid VARCHAR(100) ;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE v_SQLSTATE CHAR(5) DEFAULT '00000'; -- (2)
DECLARE cursor1 CURSOR with hold FOR
SELECT ID,SQLTEXT FROM test;--
DECLARE CONTINUE HANDLER FOR SQLWARNING, SQLEXCEPTION, NOT FOUND
SET p_SQLSTATE = SQLSTATE;
DECLARE GLOBAL TEMPORARY TABLE Rslt (
sql_id varchar(100),
cnt Varchar(4),
sql_state varchar(6)
)
on commit
preserve rows
not logged ;
Open cursor1;
A:
Loop
fetch cursor1 into v_Tid, v_Tsql;
insert into session.Rslt values(v_Tsql, v_Tid, '0');
commit;
call sysproc.admin_cmd('export to c:\test\test.csv of del select * from session.Rslt') ;
end loop A;
close cursor1;
drop table session.Rslt;
END
{code}