有两个表 vac_user_test 和 cbd.temp_user_test,两个表表结构不同,cbd.temp_user_test 中有 10W 条数据,vac_user_test 无数据
现在想把 cbd.temp_user_test 中的数据按照对应规则导入到 vac_user_test 中
写了个存储过程,执行时间是 50s
使用语句执行时间是 9s
想知道如何优化存储过程
如果cbd.temp_user_test中的数据扩展到 2000W,那个执行效率高?
表结构如下:
SQL> desc vac_user_test
Name Null? Type
----------------------------------------------------------------------------------- -------- --------------------------------------------------------
MDN NOT NULL VARCHAR2(30)
IMSI VARCHAR2(50)
USERTYPE NOT NULL VARCHAR2(2)
USERSTAT NOT NULL VARCHAR2(2)
USERBRAND VARCHAR2(5)
USERSCPTYPE VARCHAR2(1)
USERPREPAIDID VARCHAR2(20)
UPDATEDATE NOT NULL VARCHAR2(14)
CREATEBY NUMBER(1)
CREATETIME DATE
UPDATETIME DATE
LASTUPDATETYPE NUMBER(1)
USERSERVICETYPE NUMBER(1)
IFSENT NUMBER(1)
SQL> desc cbd.temp_user_test
Name Null? Type
----------------------------------------------------------------------------------- -------- --------------------------------------------------------
USER_NUMBER NOT NULL VARCHAR2(30)
NETWORK_TYPE NOT NULL NUMBER(2)
REGISTER_DATE DATE
PAYMENT_TYPE NOT NULL NUMBER(2)
STATUS NOT NULL NUMBER(2)
IMSI VARCHAR2(30)
BRAND VARCHAR2(50)
UPDATE_DATE DATE
SCP_TYPE NUMBER(2)
PREPAID_ID VARCHAR2(30)
存储过程如下:- CREATE OR REPLACE PROCEDURE INSERTUSER(resultCode out number,message out varchar2)
- IS
- exec_time varchar2(14);
- sqlstr varchar2(2000);
- TYPE CURSOR_TYPE IS REF CURSOR;
- cur_user CURSOR_TYPE;
- TYPE U_TYPE IS RECORD(
- v_mdn cbd.temp_user_test.user_number%TYPE,
- v_imsi cbd.temp_user_test.imsi%TYPE,
- v_payment_type cbd.temp_user_test.payment_type%TYPE,
- v_status cbd.temp_user_test.status%TYPE,
- v_brand cbd.temp_user_test.brand%TYPE,
- v_scp_type cbd.temp_user_test.scp_type%TYPE,
- v_prepaid_id cbd.temp_user_test.prepaid_id%TYPE,
- v_update_date cbd.temp_user_test.update_date%TYPE,
- v_register_date cbd.temp_user_test.register_date%TYPE,
- v_network_type cbd.temp_user_test.network_type%TYPE);
- user_row U_TYPE;
- BEGIN
- --- programe exec starttime
- SELECT to_char(sysdate,'MM-DD HH24:MI:SS') INTO exec_time FROM dual;
- DBMS_OUTPUT.put_line('start : '||exec_time);
- resultCode := 0;
- message := 'success';
- BEGIN
- sqlstr := 'SELECT u.user_number,u.imsi,u.payment_type,';
- sqlstr := sqlstr || 'decode(u.status,0,10,1,11,2,14,3,30),u.brand,u.scp_type,u.prepaid_id,';
- sqlstr := sqlstr || 'u.update_date,u.register_date,decode(u.network_type,0,0,8,1,2,2,3,3,4,4,1,5,7,6,6,7,5,8,9) ';
- sqlstr := sqlstr || ' FROM cbd.temp_user_test u';
- sqlstr := sqlstr || '';
- OPEN cur_user FOR sqlstr;
- LOOP
- FETCH cur_user INTO user_row;
- EXIT WHEN cur_user%NOTFOUND;
- sqlstr := 'insert into vac_user_test(MDN,IMSI,USERTYPE,USERSTAT,USERBRAND,USERSCPTYPE,USERPREPAIDID,';
- sqlstr := sqlstr || 'UPDATEDATE,CREATEBY,CREATETIME,UPDATETIME,LASTUPDATETYPE,USERSERVICETYPE,IFSENT)';
- sqlstr := sqlstr || 'values (:MDN,:IMSI,:USERTYPE,:USERSTAT,:USERBRAND,:USERSCPTYPE,:USERPREPAIDID,';
- sqlstr := sqlstr || ':UPDATEDATE,3,:CREATETIME,:UPDATETIME,1,:USERSERVICETYPE,1)';
- execute immediate sqlstr using user_row.v_mdn,user_row.v_imsi,user_row.v_payment_type,
- user_row.v_status,user_row.v_brand,user_row.v_scp_type,user_row.v_prepaid_id,
- nvl(to_char(user_row.v_update_date,'YYYYMMDDHH24MISS'),to_char(user_row.v_register_date,'YYYYMMDDHH24MISS')),
- user_row.v_register_date,user_row.v_update_date,user_row.v_network_type;
- END LOOP;
- COMMIT;
- CLOSE cur_user;
- END;
- --- programe exec endtime
- SELECT to_char(sysdate,'MM-DD HH24:MI:SS') INTO exec_time FROM dual;
- DBMS_OUTPUT.put_line('end : '||exec_time);
- END INSERTUSER;
- /
复制代码 执行的 sql 语句如下:- insert into vac_user_test(MDN,IMSI,USERTYPE,USERSTAT,USERBRAND,USERSCPTYPE,USERPREPAIDID,
- UPDATEDATE,CREATEBY,CREATETIME,UPDATETIME,
- LASTUPDATETYPE,USERSERVICETYPE,IFSENT)
- select u.user_number,u.imsi,u.payment_type,decode(u.status,0,10,1,11,2,14,3,30),u.brand,u.scp_type,u.prepaid_id,
- nvl(to_char(u.update_date,'YYYYMMDDHH24MISS'),to_char(u.register_date,'YYYYMMDDHH24MISS')),3,u.register_date,u.update_date,
- 1,decode(u.network_type,0,0,8,1,2,2,3,3,4,4,1,5,7,6,6,7,5,8,9),1
- from cbd.temp_user_test u;
复制代码 请各位老师和同学帮我看看是哪的问题?
|