sqlload 模板二


LOAD DATA
INFILE '/.../e.txt'
BADFILE '/.../e.bad'
DISCARDFILE '/.../e.dsc'
APPEND INTO TABLE table_name
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(   rx_fill_nbr,
    clm_dt date "mm/dd/yyyy"
)
sqlldr userid=username/password@databaseName control=/.../ctl_name.ctl  log=/directory/log_name.log  parallel=true
--direct=true 
----------------------------------------

rx_fill_nbr NULLIF (rx_fill_nbr="NULL"),--默认可以为空

Fields terminated by ";" Optionally enclosed by '"'

insert,为缺省方式,在数据装载开始时要求表为空
append,在表中追加新记录
replace,删除旧记录,替换成新装载的记录

fields terminated by X'09'  字段终止于X'09',是一个制表符(TAB)
--------------------------------------------

跳过某一行:
OPTIONS(SKIP=1)
  LOAD DATA
  TRUNCATE INTO TABLE T1
   FIELDS TERMINATED BY ','
  ( field1,
  field2 FILLER,
  field3
   )
-------------------------------------------------------
导入多行记录:
 LOAD DATA
  INFILE *
  concatenate 3 // 通过关键字concatenate 把几行的记录看成一行记录
  INTO TABLE DEPT
 replace
  FIELDS TERMINATED BY ','
  (DEPTNO,
  DNAME "upper(:dname)",
  LOC "upper(:loc)",
  LAST_UPDATED date 'dd/mm/yyyy'
  )
  BEGINDATA
  10,Sales, // 其实这3行看成一行 10,Sales,Virginia,1/5/2000
  Virginia,
  1/5/2000
-------------------------------------------------------
导入数据时修改数据:
  在导入数据到数据库时,可以修改数据。注意,这仅适合于常规导入,并不适合 direct导入方式.如:
  LOAD DATA
  INFILE *
   INTO TABLE modified_data
  ( rec_no "my_db_sequence.nextval",
    region CONSTANT '31',
    time_loaded "to_char(SYSDATE, 'HH24:MI')",
    data1 POSITION(1:5) ":data1/100",
    data2 POSITION(6:15) "upper(:data2)",
    data3 POSITION(16:22)"to_date(:data3, 'YYMMDD')"
   )
   BEGINDATA
   11111AAAAAAAAAA991201
   22222BBBBBBBBBB990112

   LOAD DATA
   INFILE 'mail_orders.txt'
   BADFILE 'bad_orders.txt'
   APPEND
  INTO TABLE mailing_list
  FIELDS TERMINATED BY ","
   ( addr,
    city,
    state,
    zipcode,
    mailing_addr "decode(:mailing_addr, null, :addr, :mailing_addr)",
    mailing_city "decode(:mailing_city, null, :city, :mailing_city)",
    mailing_state
   )

  将数据导入多个表:
  如:
  LOAD DATA
  INFILE *
  REPLACE
   INTO TABLE emp
  WHEN empno != ' '
  ( empno POSITION(1:4) INTEGER EXTERNAL,
  ename POSITION(6:15) CHAR,
  deptno POSITION(17:18) CHAR,
  mgr POSITION(20:23) INTEGER EXTERNAL
  )
   INTO TABLE proj
  WHEN projno != ' '
  ( projno POSITION(25:27) INTEGER EXTERNAL,
  empno POSITION(1:4) INTEGER EXTERNAL
  )
   导入选定的记录:
  如下例: (01) 代表第一个字符, (30:37) 代表30到37之间的字符:
  LOAD DATA
   INFILE 'mydata.dat' BADFILE 'mydata.bad' DISCARDFILE 'mydata.dis'
   APPEND
  INTO TABLE my_selective_table
  WHEN (01) <> 'H' and (01) <> 'T' and (30:37) = '19991217'
  (
  region CONSTANT '31',
  service_key POSITION(01:11) INTEGER EXTERNAL,
  call_b_no POSITION(12:29) CHAR
  )

  导入时跳过某些字段:
  可用 POSTION(x:y) 来分隔数据. 在Oracle8i中可以通过指定 FILLER 字段实现。FILLER 字段用来跳过、忽略导入数据文件中的字段.如:
  LOAD DATA
  TRUNCATE INTO TABLE T1
   FIELDS TERMINATED BY ','
  ( field1,
  field2 FILLER,
  field3
   )


                     

你可能感兴趣的:(load)