配置 oracle資料匯出工具sqluldr2

2021-08-31 07:13:39 字數 4450 閱讀 9167

分別對應32為,64位的win和linux平台

安裝步驟

1.需要安裝oracle_client

2.複製sqluldr2_linux32_10204.bin(64位系統用sqluldr2_linux64_10204.bin)到$oracle_home的bin目錄,重新命名為sqluldr2.bin

3.修改 $home目錄下.bash_profile 增加如下環境變數

export ld_library_path=$oracle_home/bin:$oracle_home/lib:/lib:/usr/lib  

4.驗證

-bash-3.2$ sqluldr2.bin

license: free for non-commercial useage, else 100 usd per server.

usage: sqluldr2 keyword=value [,keyword=value,...]

for field and record, you can use '0x' to specify hex character code,

\r=0x0d \n=0x0a |=0x7c ,=0x2c, \t=0x09, :=0x3a, #=0x23, "=0x22 '=0x27 

linux下用法:

get_tables.sql為預定義匯出sql

-bash-3.2$ sqluldr2.bin user=userid/keyword@db_name sql=get_tables.sql head=no file=/oracle/oradata/backup/stock.csv

0 rows exported at 2014-05-06 11:49:25, size 0 mb.

1000000 rows exported at 2014-05-06 11:49:28, size 24 mb.

2000000 rows exported at 2014-05-06 11:49:32, size 48 mb.

3000000 rows exported at 2014-05-06 11:49:35, size 76 mb.

4000000 rows exported at 2014-05-06 11:49:38, size 100 mb.

5000000 rows exported at 2014-05-06 11:49:41, size 124 mb.

6000000 rows exported at 2014-05-06 11:49:44, size 152 mb.

7000000 rows exported at 2014-05-06 11:49:47, size 176 mb.

8000000 rows exported at 2014-05-06 11:49:50, size 204 mb.

9000000 rows exported at 2014-05-06 11:49:53, size 228 mb.

10000000 rows exported at 2014-05-06 11:49:56, size 252 mb.

11000000 rows exported at 2014-05-06 11:49:59, size 280 mb.

12000000 rows exported at 2014-05-06 11:50:02, size 304 mb.

13000000 rows exported at 2014-05-06 11:50:05, size 328 mb.

14000000 rows exported at 2014-05-06 11:50:08, size 356 mb.

15000000 rows exported at 2014-05-06 11:50:11, size 380 mb.

16000000 rows exported at 2014-05-06 11:50:14, size 408 mb.

17000000 rows exported at 2014-05-06 11:50:17, size 432 mb.

18000000 rows exported at 2014-05-06 11:50:20, size 456 mb.

19000000 rows exported at 2014-05-06 11:50:23, size 484 mb.

20000000 rows exported at 2014-05-06 11:50:27, size 508 mb.

21000000 rows exported at 2014-05-06 11:50:30, size 531 mb.

21877116 rows exported at 2014-05-06 11:50:33, size 558 mb.

output file /oracle/oradata/backup/f_stock.csv closed at 21877116 rows, size 558 mb.

-bash-3.2$ 

下為windows平台使用方法:

**例子1:

sqluldr2.exe user=使用者/密碼@tnsquery="select   /*+ parallel(8)  */  *from cs_*** dt,cfg_*** devdim105 wheredt.starttime>=to_date('2012-06-27 00:00:00','yyyy-mm-dd hh24:mi:ss') and dt.starttime<=to_date('2012-06-2700:01:59','yyyy-mm-dd hh24:mi:ss') and dt.msc= devdim105.mapvalue(+) anddevdim105.deviceid=15 " head=yes file=f:\cs_***_test.csv

**例子2(這種方式用於匯出的查詢sql很長,那麼就把sql寫在123.sql檔案裡 ):

sqluldr2.exe user=使用者/密碼@tns  sql=123.sql head=yes file=f:\cs_***_test.csv

3.在cmd裡,直接把步驟2的**例子1 ,貼進去執行。

注:如果執行報報錯,就有可能是環境變數path的問題,還有就是plsql需要的oci.dll檔案等多個dll檔案,請放在sqluldr2的目錄下。

4.檢視結果f:\cs_***_test.csv

5.開啟csv裡面的內容,就可以用sqlldr進行 入庫。

字符集的控制:

預設情況下, oracle客戶端程式的字符集都由環境變數(nls_lang)決定, 很多時侯會因為忽略了環境變數的檢查, 尤其是在shell或perl指令碼中呼叫時, 導致匯出的資料變成了亂碼. 在oci 8的介面中, 可以使用ocienvnlscreate函式在程式中指定客戶端字符集, 從而跳過環境變數的影響, 於是就在sqluldr2工具中新增了兩個選項, 用於指定匯出時了字符集.

新的sqluldr2工具命令列幫助如下所示:

usage: sqluldr2 keyword=value [,keyword=value,...]

for field and record, you can use '0x' to specify hex character code,

\r=0x0d \n=0x0a |=0x7c ,=0x2c, \t=0x09, :=0x3a, #=0x23, "=0x22 '=0x27

在乙個gbk的資料庫中存入"中國"兩個字, 然後以gbk和utf8兩種不同的字符集進行匯出, 在命令列指定字符集設定.

c:\>sqluldr2 scott/tiger query=test charset=zhs16gbk

0 rows exported at 2010-06-24 09:12:27, size 0 mb.

1 rows exported at 2010-06-24 09:12:27, size 0 mb.

output file uldrdata.1.txt closed at 1 rows, size 0 mb.

c:\>dir uldrdata.1.txt

2010-06-24  09:12                5 uldrdata.1.txt

c:\>sqluldr2 scott/tiger query=test  charset=utf8

0 rows exported at 2010-06-24 09:12:42, size 0 mb.

1 rows exported at 2010-06-24 09:12:42, size 0 mb.

output file uldrdata.1.txt closed at 1 rows, size 0 mb.

c:\>dir uldrdata.1.txt

2010-06-24  09:12                7 uldrdata.1.txt

用gbk匯出時, 檔案大小為5個位元組, 兩個漢字(乙個漢字佔兩個位元組)再加乙個換行符. 而用utf8匯出時, 檔案大小為7, 兩個漢字(乙個漢字佔三個位元組)加上乙個換行符. 如果用sqluldr2為特定的資料庫寫指令碼程式時, 在命令列指定字符集, 將使指令碼更加強壯.

Oracle匯入匯出工具

oracle匯入匯出工具 exp和 imp介紹 1 exp 資料匯出工具 有三種主要的方式 完全 使用者 表 1 完全 將整個oracle資料庫中的所有物件 使用者等匯出。2 使用者模式 將指定使用者的所有物件和物件中的資料匯出。3 表模式 將指定使用者的指定資料表進行匯出。2 imp 資料匯入工具...

sqoop匯出工具

sqoop的匯出工具是把hdfs上檔案中的資料匯出到mysql中 mysql中的表 現在在linux上建立乙個檔案,並把這個檔案上傳到hdfs上 cat person.txt 7,no7,77 8,no8,88 hadoop fs mkdir person export hadoop fs put ...

mysqldump 資料匯出工具使用

mysqldump客戶端工具用來備份資料庫或者在不同資料庫之前進行資料遷移,有下面三種方式來呼叫 mysqldump options db name tables 備份單個資料庫或者庫中部分資料表 mysqldump options database db1 db2 db3 備份指定乙個或者多個資料...