批量修改tacustomer表(5万-几十万不等),耗时几个小时,导致tacustomer锁表时间过长,引起ccentric,网站无法登录。由于该表上有3个触发器,11个索引,更新效率很低,同时该表是客户信息表,访问频度非常高。
现执行语句为:
/* Formatted on 2008/04/28 12:50 (Formatter Plus v4.8.7) */
UPDATE ta.tacustomer t
SET t.lastupdatedate = SYSDATE, t.lastupdateway = :"SYS_B_0", t.signofvalidaddress = :"SYS_B_1"
WHERE customerid IN (SELECT customerid FROM z_temp_qxyj_2)
改成逐条修改,分块提交(比如每次1000提交)方式,会好一些?(使用sqlplus,导出到一个临时文本文件tmp.sql中,再执行该文本文件tmp.sql即可,见附件) 在命令行上执行命令:
D:/sqlplus callcenter/password@jsdc @sqlplus.sql
-- 附录A:sqlplus.sql的脚本代码
set
termout
off
SET linesize 1024
set heading off
set feedback off
SET echo off
SET pagesize 0
SET trimout on
SET trimspool on
-- 输出到临时文件
spool c: mp.sql
-- 分块提交(块大小可调整)
select ' UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = '' C '' , signofvalidaddress = '' 0 '' WHERE customerid = ' || custumerid || ' ; '
|| ( CASE WHEN MOD(ROWNUM, 10 ) = 0 THEN chr( 10 ) || ' COMMIT; ' ELSE '' END )
-- SELECT *
from z_temp_qxyj t
WHERE ROWNUM < 109
;
-- 最后一个块的提交
SELECT ' COMMIT; ' FROM DUAL;
spool off ;
-- 执行脚本批量提交(酌情打开)
-- start c: mp.sql
exit
SET linesize 1024
set heading off
set feedback off
SET echo off
SET pagesize 0
SET trimout on
SET trimspool on
-- 输出到临时文件
spool c: mp.sql
-- 分块提交(块大小可调整)
select ' UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = '' C '' , signofvalidaddress = '' 0 '' WHERE customerid = ' || custumerid || ' ; '
|| ( CASE WHEN MOD(ROWNUM, 10 ) = 0 THEN chr( 10 ) || ' COMMIT; ' ELSE '' END )
-- SELECT *
from z_temp_qxyj t
WHERE ROWNUM < 109
;
-- 最后一个块的提交
SELECT ' COMMIT; ' FROM DUAL;
spool off ;
-- 执行脚本批量提交(酌情打开)
-- start c: mp.sql
exit
-- 附录B:输出sql样例
UPDATE
ta.tacustomer
SET
lastupdatedate
=
SYSDATE, lastupdateway
=
'
C
'
, signofvalidaddress
=
'
0
'
WHERE
customerid
=
1001093476
;
UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = ' C ' , signofvalidaddress = ' 0 ' WHERE customerid = 1001093478 ;
COMMIT ;
UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = ' C ' , signofvalidaddress = ' 0 ' WHERE customerid = 1001093525 ;
UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = ' C ' , signofvalidaddress = ' 0 ' WHERE customerid = 1001093527 ;
COMMIT ;
UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = ' C ' , signofvalidaddress = ' 0 ' WHERE customerid = 1001093478 ;
COMMIT ;
UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = ' C ' , signofvalidaddress = ' 0 ' WHERE customerid = 1001093525 ;
UPDATE ta.tacustomer SET lastupdatedate = SYSDATE, lastupdateway = ' C ' , signofvalidaddress = ' 0 ' WHERE customerid = 1001093527 ;
COMMIT ;