oracle异常处理00103 loop异常继续循环 异常处理选点

loop循环希望异常处理后继续,异常处理选点很重要。
CREATE OR REPLACE PROCEDURE P_G_ZTE_CELL_SUM41(V_BEGIN IN VARCHAR,
V_END IN VARCHAR) AS
V_EXIST INT;
V_TIME_BEGIN DATE := TO_DATE(V_BEGIN, 'YYYY-MM-DD HH24');
V_TIME_END DATE := TO_DATE(V_END, 'YYYY-MM-DD HH24');

TYPE T_VARRAY IS VARRAY(18) OF VARCHAR2(50);
V_VAR T_VARRAY := T_VARRAY('PGZTECELLSUM0', 'PGZTECELLSUM1');
BEGIN
FOR I IN 1 .. V_VAR.COUNT LOOP
SELECT COUNT(1)
INTO V_EXIST
FROM USER_TABLES
WHERE TABLE_NAME = V_VAR(I);
IF V_EXIST > 0 THEN
EXECUTE IMMEDIATE ('DROP TABLE ' || V_VAR(I));
END IF;
END LOOP;

WHILE V_TIME_BEGIN <= V_TIME_END LOOP
--检查记录数量
DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_TIME_BEGIN, 'YYYY-MM-DD HH24'));
SELECT COUNT(1)
INTO V_EXIST
FROM G_ZTE_620_CELL
WHERE COLLECTTIME = V_TIME_BEGIN;
DBMS_OUTPUT.PUT_LINE('G_ZTE_620_CELL 记录数量: ' || V_EXIST);

--求和插入小时表
BEGIN
--异常处理开始点
INSERT INTO G_ZTE_620_CELL_H
SELECT TRUNC(COLLECTTIME, 'HH24') COLLECTTIME,
BSCID,
SITEID,
BTSID,
sum(C100030001) C100030001,
...
sum(C100030245) C100030245
FROM G_ZTE_620_CELL
WHERE TRUNC(COLLECTTIME, 'HH24') = V_TIME_BEGIN
GROUP BY TRUNC(COLLECTTIME, 'HH24'), BSCID, SITEID, BTSID;
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
DBMS_OUTPUT.PUT_LINE('G_ZTE_620_CELL_H 试图插入重复数据,已经阻止。'); -- ORA-00001 SQLCODE = -1 向唯一索引中插入重复数据
END; --异常处理结束点
DBMS_OUTPUT.PUT_LINE('G_ZTE_620_CELL_H 按小时求和完成');
V_TIME_BEGIN := V_TIME_BEGIN + 1 / 24;

END LOOP;

END;

你可能感兴趣的:(oracle异常处理00103 loop异常继续循环 异常处理选点)