用SQL*Loader將Excel資料匯出到Oracle

來源:互聯網
上載者:User

 

實現目的:往oracle資料庫中,插入excel檔案中的資料

 

實現步驟:

 

1、開啟MicroSoft Excel 2000

 

2、檔案(F)→建立(N)→活頁簿→

 

3、輸入資料後,存檔為test.xls,

 

4、檔案(F)→另存新檔(A)→

 

檔案類型為:定位字元分隔,起名為text.txt,儲存到C:

 

 

 

5、須先建立表結構:

連入SQL*Plus,以system/manager使用者登入,

SQL> conn system/manager

 

建立表結構

SQL> create table test

    (

    id       number,        --序號

    username    varchar2(10),     --使用者名稱

    password    varchar2(10),     --密碼

    sj       varchar2(20)      --建立日期

    );

 

6、建立SQL*Loader輸入資料所需要的檔案,均儲存到C:,用記事本編輯:

控制檔案:input.ctl,內容如下:

 

  load data           --1、控制檔案標識

  infile 'test.txt'       --2、要輸入的資料檔案名為test.txt

  append into table test    --3、向表test中追加記錄

  fields terminated by X'09'  --4、欄位終止於X'09',是一個定位字元(TAB)

  (id,username,password,sj)   -----定義列對應順序

 

a、insert,為預設方式,在資料裝載開始時要求表為空白

b、append,在表中追加新記錄

c、replace,刪除舊記錄,替換成新裝載的記錄

d、truncate,同上

 

7、在DOS視窗下使用SQL*Loader命令實現資料的輸入

 

C:>sqlldr userid=system/manager control=input.ctl

 

  預設記錄檔名為:input.log

  預設壞記錄檔案為:input.bad

 

如果是遠程對資料庫進行匯入操作,則輸入字串應改為:

C:>sqlldr userid=system/manager@serviceName_192.168.1.248 control=input.ctl

 

8、串連到SQL*Plus中,查看是否成功輸入,可比較input.log與原test.xls檔案,查看資料是否全部匯入,是否匯入成功.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.