现在项目经理让我优化公司存储过程,要求把A系统的部分表数据查出来,然后按照B系统的表结构插入到B系统里。存储过程写好了,但是速度很慢
现在的情况:
1、数据量在400W左右,需要大批量查询插入
2、现在执行一次要7个小时左右才能结束
3、该存储过程维护了B系统4张表的数据,都来自A系统即@LD
下边是存储过程代码,求高人指教。
CREATE OR REPLACE PROCEDURE P_CREATE_CUSTOMER AS
V_CUSTOMERID NUMBER(18);
V_CUSTOMERNO VARCHAR2(7);
ld_fr_date DATE := SYSDATE;
ld_end_date DATE;
ld_etr_date date := TO_DATE('1900-12-12', 'yyyy-mm-dd');
CURSOR CUR_CUST_ALL IS
SELECT S_CUSTOMER.NEXTVAL, TO_CHAR(CUST_ID)
FROM TB_AC001@LD;--where cust_id < 1010000
BEGIN
--请空图片表
--DELETE FROM CUR_PICTURE;
OPEN CUR_CUST_ALL;
LOOP
FETCH CUR_CUST_ALL
INTO V_CUSTOMERID, V_CUSTOMERNO;
--DBMS_OUTPUT.PUT_LINE(V_PIC_ID);
EXIT WHEN CUR_CUST_ALL %NOTFOUND;
--新增客户主表信息 TB_AC001@LD -->>CUSTOMER
INSERT INTO CUSTOMER
(CUSTOMERID, CUSTOMERNO, IS_MAIL, IS_DM, HAPPY_CALL, CUS_TYPE)
SELECT V_CUSTOMERID,
V_CUSTOMERNO,
DECODE(MAIL_SEND_YN, 'Y', '1', 'N', '0', '0'),
DECODE(DM_SEND_YN, 'Y', '1', 'N', '0', '0'),
DECODE(HAPPY_CALL_YN, 'Y', '1', 'N', '0', '0'),
1
FROM TB_AC001@LD
WHERE CUST_ID = V_CUSTOMERNO;
--在表CUS_PERSONAL表中插入数据
INSERT INTO CUS_PERSONAL
(CUSTOMERID,
BUSI_CODE,
CUS_CAT_ID,
NAME_CN,
GENDER,
REGION_ID,
CRED_TYP_ID,
CRED_NUM,
BIRTHDAY,
CUS_TRA_ID,
JOB_TYP_ID,
CUS_GRA_ID,
HAS_MARRIED,
SALARY_ID,
CUS_FROM_ID,
HAS_CHECKED,
STA_ID,
CRE_USE_ID,
CRE_DAT,
UPD_USE_ID,
UPD_DAT,
EXT1,
EXT2,
EXT3,