標籤: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工具的使用