sql*loader的實驗一,sql*loader實驗

來源:互聯網
上載者:User

sql*loader的實驗一,sql*loader實驗

目的:將txt中的資料匯入到資料庫的一個表中

第一步:scott建立一個空表

create table family(id number(10),name varchar(20),sal number(20),total number(30));

第二步:建立txt資料檔案:

vi /oracle/input.txt

1,clark,4000,50000
2,saber,4100,40000

第三步:建立sql*loader的輸入控制檔案:

vi /oracle/input.ctl

load data
infile '/oracle/input.txt'
into table family
fields terminated by ','
(id,name,sal,total)

第四步:執行匯入

sqlldr scott/tiger control='/oracle/input.ctl'  log='/oracle/input.log'

提示匯入完畢:

Commit point reached - logical record count 2

第五步:檢查表的情況:

SQL> select * from family;

 ID NAME          SAL TOTAL
---------- -------------------- ---------- ----------
  1 clark        4000 50000
  2 saber        4100 40000

 


sql*loader是個什東西

sql*loader 是一個程式, 用來把 文字檔裡面的資料, 匯入到 Oracle 資料庫裡面。

下面是一個簡單的例子:

SQL*Loader

首先需要一個 控制檔案test_main.ctl,內容如下:
LOAD DATA
INFILE *
INTO TABLE test_main
FIELDS TERMINATED BY ','
(ID, VALUE)
BEGINDATA
1,Test

其中,
第一行LOAD DATA意思是告訴SQL*Loader,要幹啥? 這裡是載入資料。
第二行INFILE *意思是資料從哪裡來? 這裡是包含在控制檔案中。
第三行INTO TABLE 意思是資料要導到哪裡? 這裡是要到 test_main 表。
第四行FIELDS TERMINATED BY意思是資料之間用什麼符號分隔? 這裡是用 逗號 分隔。
第五行是資料要按什麼順序寫到列裡面
第六行BEGINDATA是告訴SQL*Loader,後面的都是資料了。

然後開始運行 sqlldr 程式

D:\temp>sqlldr userid=test/test123 control=test_main.ctl
SQL*Loader: Release 10.2.0.1.0 - Production on 星期日 3月 13 14:58:22 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL*Loader-601: 對於 INSERT 選項, 表必須為空白。表 TEST_MAIN 上出錯

在 SQL Plus 中,
SQL> truncate table test_main;
表被截斷。
以後,再次測試執行

D:\temp>sqlldr userid=test/test123 control=test_main.ctl
SQL*Loader: Release 10.2.0.1.0 - Production on 星期日 3月 13 14:58:56 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
達到提交點 - 邏輯記錄計數 1
 
SQL*Loader-350

SQL*Loader-350: 語法錯誤位於第 6 行,一般發生在 ParFile 內容中。

請仔細檢查 ParFile中的內容文法格式。如果還沒能解決,請追問。
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.