TERMINATED BY ',' a data string,
ENCLOSED BY '"' "a data string"
TERMINATED BY ',' ENCLOSED BY '"' "a data string",
ENCLOSED BY '(' AND ')' (a data string)
-- appache access logfile load sample control file
load data -- 新しくデータロードが開始される
infile 'access_log' -- ロードするデータが入っているファイル名
badfile 'access_log.bad' -- 拒否レコードが書き込まれるファイル名
discardfile 'access_log.dsc' -- 廃棄レコードが書き込まれるファイル名
insert -- すでにデータが存在する場合のオプション APPEND,REPLACE,TRUNCATE
into table exam.apache_access_log --
( ip_address position(*) char terminated by whitespace
, user_inf position(*) char terminated by whitespace
, user_id position(*) char terminated by whitespace
, req_date position(*) char enclosed by '[' and ']'
, request position(*) char enclosed by '"' and '"'
, status_cd position(*) char terminated by whitespace
, res_size position(*) char terminated by whitespace
, referer position(*) char enclosed by '"' and '"'
, user_agent position(*) char enclosed by '"' and '"'
)
実行
apache のアクセスログを、access_log.datに変更して、以下を実行
$sqlldr exam/abc123 apache_access_log.ctl
SQL*Loader: Release 10.2.0.1.0 - Production on Sat Jul 11 22:05:04 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit point reached - logical record count 64
Commit point reached - logical record count 128
:
ダイレクト・パス・ロードで実行の例
$ sqlldr exam/abc123 apache_access_log.ctl direct=true
SQL*Loader: Release 10.2.0.1.0 - Production on Sun Jul 12 00:18:28 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Load completed - logical record count 5872.
取り込まれた
select * from exam.apache_access_log;
ユーザーエージェントを調べてみる
select user_agent,count(user_agent) from exam.apache_access_log
group by user_agent
order by 2 desc