DROP PROCEDURE MYLIB.TestErrorHandler;
CREATE PROCEDURE MYLIB.TestErrorHandler ()
LANGUAGE SQL
BEGIN
DECLARE prodnum DECIMAL(6,0);
DECLARE at_end INT DEFAULT 0;
DECLARE SQLCODE INT DEFAULT 0;
DECLARE not_found CONDITION FOR '02000';
DECLARE c1 CURSOR FOR
SELECT DISTINCT (MYPRODNUM) FROM MYLIB.MYTABLE1 WHERE MYCOLUMNNAME ='value';
DECLARE EXIT HANDLER FOR not_found
SET at_end =1;
OPEN c1;
FETCH c1 INTO prodnum;
WHILE at_end =0 DO
FETCH c1 INTO prodnum;
END WHILE ;
CLOSE c1;
INSERT INTO MYLIB.MYTABLE2 VALUES('not exited if no results found');
END;
CALL MYLIB.TestErrorHandler();
I try to run the above example.
I assume that if the select returns some records, the exit handler will not be invoked.
The exit handler invokes only if there are no records found.
In the example, the select statement returns some records but the insert does not takes place.
How does the exit handler works in the above example??