'Cursor not in a valid state' -
10-29-2007
, 07:20 AM
Hello all,
I am facing a problem when running the following function:
alter FUNCTION rowtocol( IN qry varchar(4000),p_dlmtr
varchar(10) DEFAULT ',' ) RETURNS varchar
BEGIN
DECLARE lc_colval VARCHAR(4000);
DECLARE lc_str VARCHAR(32767);
DECLARE CUR_REC CURSOR USING qry;
DECLARE err_notfound
EXCEPTION FOR SQLSTATE '02000';
SET lc_colval='';
SET lc_str='';
message 'qry='||qry to client;
message 'before cursor' to client;
OPEN CUR_REC;
notes_loop:
LOOP
FETCH CUR_REC INTO lc_colval;
if SQLstate <> 0 then leave notes_loop;
end if;
message 'inside cursor' to client;
set lc_str=lc_str || p_dlmtr || lc_colval;
message 'lc_str='||lc_str to client;
END LOOP notes_loop;
CLOSE cur_rec;
RETURN SUBSTR(lc_str,2);
EXCEPTION
WHEN OTHERS THEN
message ' Others sqlstate = ',sqlstate to
client;
END;
I am getting an error 'Cursor not in a valid state' when I
try to run this function. Also, when I try using sqlcode =
err_notfound, then it goes into an infinite loop.
SQL Anywhere Version: 10.0.0.2829
Could anyone please check and suggest a solution?
Thanks,
Pradeep |