oracle异常处理00103|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;
推荐阅读
- Java|Java OpenCV图像处理之SIFT角点检测详解
- 事件处理程序
- 爬虫数据处理HTML转义字符
- oracle|oracle java jdk install
- python-安装sublime遇到异常
- Android|Android BLE蓝牙连接异常处理
- 【冷处理】亲子时间管理检视Day63
- C#中类的异常处理详解
- 数据技术|一文了解Gauss数据库(开发历程、OLTP&OLAP特点、行式&列式存储,及与Oracle和AWS对比)
- JAVA图像处理系列(四)——噪声