PROCEDURE prc_trade_water_yesterday IS
-- 来源大平台前一天的数据
CURSOR cur_tbl_n_txn IS
SELECT ...,
fd61
FROM tbl_n_txn tnt,
(SELECT cups_no, MAX(cups_nm) cups_nm
FROM tablename2
GROUP BY cups_no) ti
WHERE tnt.cups_no = ti.cups_no(+)
AND tnt.tx_date = to_char(SYSDATE - 1, 'yyyymmdd');
TYPE type_array_tnt IS TABLE OF cur_tbl_n_txn%ROWTYPE INDEX BY BINARY_INTEGER;
v_tbl_n_txn type_array_tnt;
--批量每次fetch数量
v_rows NUMBER := 100;
BEGIN
v_program_name := 'pkg_name';
v_table_name := 'tablename';
prc_comm_running_log(v_program_name, SYSDATE, '开始执行', NULL);
--来源大平台
DELETE tablename1 tdtw
WHERE tdtw.tx_date = to_char(SYSDATE - 1, 'yyyymmdd')
AND tdtw.tx_source = 1;
prc_comm_running_log(v_program_name,
SYSDATE,
'删除前一天大平台的数据,以免异常重复导入: '||SQL%ROWCOUNT,
NULL);
v_insert_rows := 0;
OPEN cur_tbl_n_txn;
LOOP
FETCH cur_tbl_n_txn BULK COLLECT
INTO v_tbl_n_txn LIMIT v_rows;
FORALL i IN 1 .. v_tbl_n_txn.count
INSERT INTO tablename1
(...,
fd61
)
VALUES
(...,
v_tbl_n_txn(i).fd61
);
v_insert_rows := v_insert_rows + SQL%ROWCOUNT;
COMMIT;
EXIT WHEN cur_tbl_n_txn%NOTFOUND;
END LOOP;
CLOSE cur_tbl_n_txn;
COMMIT;
--记录结束日志及相关信息
prc_comm_running_log(v_program_name,
SYSDATE,
v_table_name || '来源大平台前一天insert行数:' ||
v_insert_rows,
NULL);
prc_comm_running_log(v_program_name, SYSDATE, '结束执行', NULL);
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
v_errm := substr(SQLERRM, 1, 255);
prc_comm_running_log(v_program_name, SYSDATE, '异常回滚', v_errm);
RAISE;
END prc_trade_water_yesterday;
-- 来源大平台前一天的数据
CURSOR cur_tbl_n_txn IS
SELECT ...,
fd61
FROM tbl_n_txn tnt,
(SELECT cups_no, MAX(cups_nm) cups_nm
FROM tablename2
GROUP BY cups_no) ti
WHERE tnt.cups_no = ti.cups_no(+)
AND tnt.tx_date = to_char(SYSDATE - 1, 'yyyymmdd');
TYPE type_array_tnt IS TABLE OF cur_tbl_n_txn%ROWTYPE INDEX BY BINARY_INTEGER;
v_tbl_n_txn type_array_tnt;
--批量每次fetch数量
v_rows NUMBER := 100;
BEGIN
v_program_name := 'pkg_name';
v_table_name := 'tablename';
prc_comm_running_log(v_program_name, SYSDATE, '开始执行', NULL);
--来源大平台
DELETE tablename1 tdtw
WHERE tdtw.tx_date = to_char(SYSDATE - 1, 'yyyymmdd')
AND tdtw.tx_source = 1;
prc_comm_running_log(v_program_name,
SYSDATE,
'删除前一天大平台的数据,以免异常重复导入: '||SQL%ROWCOUNT,
NULL);
v_insert_rows := 0;
OPEN cur_tbl_n_txn;
LOOP
FETCH cur_tbl_n_txn BULK COLLECT
INTO v_tbl_n_txn LIMIT v_rows;
FORALL i IN 1 .. v_tbl_n_txn.count
INSERT INTO tablename1
(...,
fd61
)
VALUES
(...,
v_tbl_n_txn(i).fd61
);
v_insert_rows := v_insert_rows + SQL%ROWCOUNT;
COMMIT;
EXIT WHEN cur_tbl_n_txn%NOTFOUND;
END LOOP;
CLOSE cur_tbl_n_txn;
COMMIT;
--记录结束日志及相关信息
prc_comm_running_log(v_program_name,
SYSDATE,
v_table_name || '来源大平台前一天insert行数:' ||
v_insert_rows,
NULL);
prc_comm_running_log(v_program_name, SYSDATE, '结束执行', NULL);
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
v_errm := substr(SQLERRM, 1, 255);
prc_comm_running_log(v_program_name, SYSDATE, '异常回滚', v_errm);
RAISE;
END prc_trade_water_yesterday;