存储过程执行的问题:
ERROR [42601] [IBM][DB2/NT64] SQL0104N An unexpected token "COMMIT" was found following "TAFF_STAT" ( ? , ? )". Expected tokens may include: "END-OF-STATEMENT". SQLSTATE=42601
但是如果debug就不会出错,但也没结果...
我的存储过程:
DROP PROCEDURE P_REPORT_STAFF_STAT;
SET SCHEMA = 'TB_HNYC';
CREATE PROCEDURE TB_HNYC.P_REPORT_STAFF_STAT(in p_year integer,in p_month integer)
BEGIN
DECLARE C_END INTEGER DEFAULT 0;
DECLARE UNITID INTEGER;
DECLARE not_found CONDITION FOR SQLSTATE '02000';
DECLARE CUR_STAT CURSOR FOR SELECT STAFF.C_UNITID FROM TB_INF_EMPLOYEE_REPORT STAFF GROUP BY STAFF.C_UNITID;
DECLARE CONTINUE HANDLER FOR not_found SET C_END=1;
DELETE FROM TB_REPORT_STAFF_STAT WHERE C_YEAR = p_year AND C_MONTH = p_month;
OPEN CUR_STAT;
INS_LOOP:
LOOP
FETCH FROM CUR_STAT INTO UNITID;
IF C_END=1 THEN
LEAVE INS_LOOP;
END IF;
INSERT INTO TB_REPORT_STAFF_STAT
SELECT UNITID, p_year,p_month,'123');
END LOOP;
CLOSE CUR_STAT;
COMMIT;
我考虑了DELETE,没有考虑insert没有数据的情况,都要set C_END = 0;,学习了