学习oracle sql loader 的使用[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 kb 的 blog

学习oracle sql loader 的使用

一:sql loader 的特点
oracle自己带了很多的工具可以用来进行数据的迁移、备份和恢复等工作。但是每个工具都有自己的特点。
 比如说exp和imp可以对数据库中的数据进行导出和导出的工作,是一种很好的数据库备份和恢复的工具,因此主要用在数据库的热备份和恢复方面。有着速度快,使用简单,快捷的优点;同时也有一些缺点,比如在不同版本数据库之间的导出、导入的过程之中,总会出现这样或者那样的问题,这个也许是oracle公司自己产品的兼容性的问题吧。
 sql loader 工具却没有这方面的问题,它可以把一些以文本格式存放的数据顺利的导入到oracle数据库中,是一种在不同数据库之间进行数据迁移的非常方便而且通用的工具。缺点就速度比较慢,另外对blob等类型的数据就有点麻烦了。
 
二:sql loader 的帮助

c:\>sqlldr

sql*loader: release 9.2.0.1.0 - production on 星期六 10月 9 14:48:12 2004

copyright (c) 1982, 2002, oracle corporation.  all rights reserved.


用法: sqlldr keyword=value [,keyword=value,...]

有效的关键字:

    userid -- oracle username/password
   control -- control file name
       log -- log file name
       bad -- bad file name
      data -- data file name
   discard -- discard file name
discardmax -- number of discards to allow        (全部默认)
      skip -- number of logical records to skip  (默认0)
      load -- number of logical records to load  (全部默认)
    errors -- number of errors to allow          (默认50)
      rows -- number of rows in conventional path bind array or between direct p
ath data saves
(默认: 常规路径 64, 所有直接路径)
  bindsize -- size of conventional path bind array in bytes(默认256000)
    silent -- suppress messages during run (header,feedback,errors,discards,part
itions)
    direct -- use direct path                    (默认false)
   parfile -- parameter file: name of file that contains parameter specification
s
  parallel -- do parallel load                   (默认false)
      file -- file to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions(默
认false)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unus
able(默认false)
  readsize -- size of read buffer                (默认1048576)
external_table -- use external table for load; not_used, generate_only, execute(
默认not_used)
columnarrayrows -- number of rows for direct path column array(默认5000)
streamsize -- size of direct path stream buffer in bytes(默认256000)
multithreading -- use multithreading in direct path
 resumable -- enable or disable resumable for current session(默认false)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for resumable(默认7200)
date_cache -- size (in entries) of date conversion cache(默认1000)

please note: 命令行参数可以由位置或关键字指定
。前者的例子是 'sqlload
scott/tiger foo'; 后一种情况的一个示例是 'sqlldr control=foo
userid=scott/tiger'.位置指定参数的时间必须早于
但不可迟于由关键字指定的参数。例如,
允许 'sqlldr scott/tiger control=foo logfile=log', 但是
不允许 'sqlldr scott/tiger control=foo log', 即使
参数 'log' 的位置正确。

c:\>

三:sql loader使用例子
a)sqlloader将 excel 数据导出到 oracle
1.创建sql*loader输入数据所需要的文件,均保存到c:\,用记事本编辑:
控制文件:input.ctl,内容如下:
 
  load data           --1、控制文件标识
  infile 'test.txt'       --2、要输入的数据文件名为test.txt
  append into table test    --3、向表test中追加记录
  fields terminated by x'09'  --4、字段终止于x'09',是一个制表符(tab)
  (id,username,password,sj)   -----定义列对应顺序
 
a、insert,为缺省方式,在数据装载开始时要求表为空
b、append,在表中追加新记录
c、replace,删除旧记录,替换成新装载的记录
d、truncate,同上
 
在dos窗口下使用sql*loader命令实现数据的输入
 
c:\>sqlldr userid=system/manager control=input.ctl
  默认日志文件名为:input.log
默认坏记录文件为:input.bad
 
2.还有一种方法
可以把excel文件另存为csv(逗号分隔)(*.csv),控制文件就改为用逗号分隔
load data
infile 'd:\car.csv'
append  into table t_car_temp
fields terminated by ","
(phoneno,vip_car)

b)在控制文件中直接导入数据

1、控制文件test.ctl的内容
-- the format for executing this file with sql loader is:
-- sqlldr control=<filename> be sure to substitute your
-- version of sql loader and the filename for this file.
load data
infile *
badfile 'c:\documents and settings\jackey\桌面\wmcountry.bad'
discardfile 'c:\documents and settings\jackey\桌面\wmcountry.dsc'
insert into table emccountry
fields terminated by ";" optionally enclosed by '"'
(
  countryid nullif (countryid="null"),
  countrycode,
  countryname,
  continentid nullif (continentid="null"),

本文关键:学习oracle sql loader 的使用
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top