SQLLDR


Oracle

Tips

  • ヘッダーがあるときは、OPTIONS (SKIP=xxx)で指定
  • カラムが"で囲まれている場合は、OPTIONALLY ENCLOSED BY ...で指定
  • 入力データから変換が必要なときは、ctlファイル内で指定する。
    • 日付は、to_date...をつける
  • 文字列が255文字を超えるときは、ロードエラーになる。char(...)で、最大文字列長を指定しておく
  • ctlファイルに、「Optionally Enclosed by ...」があると、空のフィールドが読み飛ばされる(<TAB><TAB>...<TAB>を、ひとつのカラムと扱う)。この場合、optionally enclosed ...を、各カラムの後につけるといいらしい(「VAR1 CHAR OPTIONALLY ENCLOSED BY '"',」とか)。
  • 説明
  • 実行:
    sqlldr userid=datamine/xxx control='filename'

  • 例1
    OPTIONS (SKIP=1)
    load data
    infile 'loaddata.txt'
    into table test.table_name
    append
    fields terminated by ',' trailing nullcols
    (
    categ_cd,
    prod_cd,
    recs,
    customers,
    ttl_amt
    )
  • 例2
    OPTIONS (SKIP=1)
    load data
    infile 'xxx.txt'
    into table yyy.zzz
    append
    fields terminated by '\t' OPTIONALLY ENCLOSED BY '"'
    trailing nullcols
    (
    col1,
    col2,
    col3 "to_date(:col3, 'YYYYMMDD')",
    col4 "to_date(:col4, 'MM/DD/YYYY HH12:MI:SS PM','NLS_DATE_LANGUAGE = American')",
    col5 char(320)
    )