今天我測試了下大量匯入匯出資料。
首先,我用spool從A資料庫中匯出資料到一個文字檔,但是發現速度有些慢。因為表中資料有120多萬條。後來就用pl/sql裡面的export query將資料匯出到csv檔案,這樣速度是快。可是這樣匯出的檔案,用sqlldr匯入到新庫中去的時候,老是報錯。而我查了資料,資料是沒有問題的。最後,我用toad裡面的"Save Grid Contents",匯出檔案格式為txt,這個時候,資料才沒有問題。可以順利的匯入到新庫中去。只是匯入速度上還不是特別滿意,但是還湊合著用了。估計是我機器效能不是太好的原因。
Save Grid Contents的按鈕如下:
樣本:
1,exp_customer.sql。 查詢資料。這個用過,但是速度不行。還不如用toad匯出資料為txt。
set echo off --是否顯示執行的命令內容
set feedback off --是否顯示 * rows selected
set heading off --是否顯示欄位的名稱
set verify off --是否顯示替代變數被替代前後的語句。fil
set trimspool off --去欄位空格
set pagesize 50000 --頁面大小
set linesize 50 --linesize設定盡量根據需要來設定,大了產生的檔案也大
define fil= 'E:/1120/customer_data.txt'
spool &fil
select customerid || '@@' || customername || '@@' || sex || '@@' ||
customertype || '@@' || papertype || '@@' || paperno || '@@' ||
customerclass || '@@' || industry || '@@' || status || '@@' ||
postlevel || '@@' || operatorcode || '@@' ||
to_char(createtime, 'yyyy-mm-dd hh24:mi:ss') || '@@' || remark || '@@' ||
busipassword || '@@' || customerprops || '@@' ||
to_char(statusupdatetime, 'yyyy-mm-dd hh24:mi:ss') || '@@' ||
passwdlevel
from t_customerinfo ci;
spool off
2,customer.ctl。控制檔案。為sqlldr所用。
OPTIONS (ROWS=10000)
LOAD DATA
INFILE 'cust_20091120.txt'
BADFILE 'customer.bad'
replace
INTO TABLE t_customerinfo
FIELDS TERMINATED BY "@@"
(customerid,customername,sex,customertype,papertype,paperno,customerclass,industry,status,postlevel,operatorcode,createtime"TO_DATE(:createtime,'yyyy-mm-dd hh24:mi:ss')",remark,busipassword,customerprops,statusupdatetime"TO_DATE(:statusupdatetime,'yyyy-mm-dd hh24:mi:ss')",passwdlevel)
3,customerimp.cmd。批次檔,執行匯入。
sqlldr lzf/lzf@testdb control=customer.ctl
最後,需要提醒的是,在匯入之前,表上面最好不要有主鍵、索引之類的,因為會非常影響速度。
我剛開始沒有刪除主鍵、索引,所以速度很慢,刪除這些東西後,匯入進去120多萬條資料,只需要1分多鐘。
等到資料全部匯入之後,在在表上建主鍵、索引。
我測試的結果是,120w條資料,建立主鍵所花費的時間是17秒。
索引則更快些。