Oracle資料庫sqlldr工具的使用

來源:互聯網
上載者:User

標籤:replace   code   varchar   分隔字元   oracl   使用者名稱   路徑   al32utf8   控制   

sqlldr匯入常值內容到資料庫表時,需要指定一個ctl檔案(控制檔案),通過該檔案來完成資料的匯入。

1 首先建立一個表student
create table student(       stu_id number(5) primary key,       stu_name varchar2(32) not null,       stu_age number(3),       stu_sex number(1),       stu_birth date);comment on table student is ‘學生表‘;comment on column student.stu_sex is ‘學生性別,0:男,1:女‘;

建立一個txt或csv檔案,檔案內容如下

10001|tom|20|0|1993-01-01
10002|mary|18|1|1995-01-11
10003|小明|19|0|1993-03-13
10004|小芳|17|1|1994-11-23

2 建立student.ctl檔案

load data
CHARACTERSET AL32UTF8
infile ‘D:\test\student.txt‘
append into table student
fields terminated by "|"
trailing nullcols
(stu_id,stu_name,stu_age,stu_se,stu_birth date "YYYY-MM-DD")

參數說明:

load data:控制檔案標識
CHARACTERSET:設定編碼格式,防止中文亂碼
infile:指定資料檔案路徑
append:指定資料裝載方式,共有四種取值:[(1) insert,為預設方式,在資料裝載開始時要求表為空白;(2 )append,刪除舊記錄(用 delete from table 語句),替換成新裝載的記錄;(3) replace,刪除舊記錄,替換成新裝載的記錄;(4) truncate,刪除舊記錄(用 truncate table 語句),替換成新裝載的記錄];這裡我指定的方式為append
fields terminated by:指定欄位間的分隔字元
trailing nullcols:表的欄位沒有對應的值時允許為空白
(stu_id,stu_name,stu_age number,stu_se number,stu_birth date "YYYY-MM-DD"):定義列順序

3 執行sqlldr匯入資料
sqlldr userid=shiot/123456 control=‘D:/test/student.ctl‘ log=‘D:/test/student.log‘ bad=‘D:/test/student.bad‘

參數說明:

userid:指定ORACLE 使用者名稱/口令    
 control:指定控制檔案路徑         
 log:指定記錄檔路徑        
 bad:指定錯誤檔案路徑

Oracle資料庫sqlldr工具的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.