CREATE OR REPLACE PROCEDURE PROC_UPDATE_TEMP(P_DAYS IN NUMBER, --执行天数 P_ROWS OUT VARCHAR2, --返回受影响的行数 P_IS_SUCCESS OUT BOOLEAN) --返回成功与否 AS V_NOW DATE := TRUNC(SYSDATE); V_BEGIN_DATE DATE; V_SECOND NUMBER; I INT := 0;BEGIN /* WHILE I < P_DAYS LOOP UPDATE T_TEMP SET TEMP_STATUS = '01', TEMP_FLAG = '0' WHERE CREATE_TIME >= V_NOW - I AND CREATE_TIME < V_NOW + 1 - I; COMMIT; I = I + 1; END LOOP;*/ FOR I IN 0 .. P_DAYS LOOP BEGIN V_BEGIN_DATE := SYSDATE; UPDATE T_TEMP SET TEMP_STATUS = '01', TEMP_FLAG = '0' WHERE CREATE_TIME >= V_NOW - I AND CREATE_TIME < V_NOW + 1 - I; P_IS_SUCCESS := TRUE; V_SECOND := (SYSDATE - V_BEGIN_DATE) * 24 * 60 * 60; --返回受影响的行数:SQL%ROWCOUNT P_ROWS := SQL%ROWCOUNT || '行被更新,耗时:' || TRUNC(V_SECOND, 2) || '秒'; DBMS_OUTPUT.PUT_LINE(P_ROWS); COMMIT; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; P_IS_SUCCESS := FALSE; END; END LOOP;END PROC_UPDATE_TEMP;
--调用存储过程DECLARE -- Boolean parameters are translated from/to integers: -- 0/1/null <--> false/true/null P_IS_SUCCESS BOOLEAN; P_ROWS VARCHAR2(200);BEGIN -- Call the procedure PKG_STL_UPDATE_BILL_DATA.PROC_STL_UPDATE_TRUNC(P_DAYS => 0, P_ROWS => P_ROWS, P_IS_SUCCESS => P_IS_SUCCESS); -- Convert false/true/null to 0/1/null --:P_IS_SUCCESS := SYS.DIUTIL.BOOL_TO_INT(P_IS_SUCCESS); dbms_output.put_line(P_ROWS); dbms_output.put_line(SYS.DIUTIL.BOOL_TO_INT(P_IS_SUCCESS));END;
--SQL%ROWCOUNT用法BEGIN UPDATE T_JOB T SET T.JOB_ID = NULL WHERE T.ID = '2013'; IF (SQL%ROWCOUNT != 1) THEN RAISE_APPLICATION_ERROR(-20001, '没有成功修改到记录'); END IF;END;RAISE_APPLICATION_ERROR的用法可参考http://www.cnblogs.com/caizhanshu/articles/1129642.html
代码迷推荐解决方案:oracle存储过程,http://www.daimami.com/oracle-develop/177537.html