您现在的位置是:首页 >

大量数据如何导入数据库 数据批量导入Oracle数据库

火烧 2023-03-16 10:05:33 1051
数据批量导入Oracle数据库   SQL*LOADER是大型数据仓库选择使用的加载方法 因为它提供了最快速的途径(DIRECT PARALLEL) 现在 我们抛开其理论不谈 用实例来使您快速掌握SQ

数据批量导入Oracle数据库  

  SQL*LOADER是大型数据仓库选择使用的加载方法 因为它提供了最快速的途径(DIRECT PARALLEL) 现在 我们抛开其理论不谈 用实例来使您快速掌握SQL*LOADER的使用方法   首先 我们认识一下SQL*LOADER   在NT下 SQL*LOADER的命令为SQLLDR 在UNIX下一般为sqlldr/sqlload   如执行 d:oracle>sqlldrSQL*Loader: Release Production on 星期二 月 : : (c) Copyright Oracle Corporation   All rights reserved

  用法: SQLLOAD 关键字 = 值 [ 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 namediscardmax Number of discards to allow        (全部默认)      skip Number of logical records to skip  (默认 )      load Number of logical records to load  (全部默认)    errors Number of errors to allow          (默认 )      rows Number of rows in conventional path bind array or beeen direct path data saves(默认: 常规路径 所有直接路径)  bindsize Size of conventional path bind array in bytes(默认 )    silent Supdivss messages during run (header feedback errors discards partitions)    direct use direct path                    (默认FALSE)   parfile parameter file: name of file that contains parameter specifications  parallel do parallel load                   (默认FALSE)      file File to allocate extents fromskip_unusable_indexes disallow/allow unusable indexes or index partitions(默认FALSE)skip_index_maintenance do not maintain indexes mark affected indexes as unusable(默认FALSE)mit_discontinued mit loaded rows when load is discontinued(默认FALSE)  readsize Size of Read buffer                (默认 )PLEASE NOTE: 命令行参数可以由位置或关键字指定 前者的例子是 sqlload scott/tiger foo ;后者的例子是 sqlload control=foo userid=scott/tiger 位置指定参数的时间必须早于但不可迟于由关键字指定的参数 例如 SQLLOAD SCott/tiger control=foo logfile=log 但 不允许 sqlload scott/tiger control=foo log 即使允许参数 log 的位置正确 d:oracle>      我们可以从中看到一些基本的帮助信息 这里 我用到的是中文的WIN  ADV SERVER   我们知道 SQL*LOADER只能导入纯文本 所以我们现在开始以实例来讲解其用法   一 已存在数据源result csv 欲倒入ORACLE中FANCY用户下     result csv内容    默认 Web 站点 : : RUNNING   other : : STOPPED   third : : RUNNING  从中 我们看出 列 分别以逗号分隔 为变长字符串   二 制定控制文件result ctl        result ctl内容 load datainfile result csv into table resultxt (resultid char terminated by website char terminated by ipport char terminated by status char terminated by whitespace)  说明   infile 指数据源文件 这里我们省略了默认的 discardfile result dsc  badfile  result bad  into table resultxt 默认是INSERT 也可以into table resultxt APPEND为追加方式 或REPLACE  terminated by  指用逗号分隔  terminated by whitespace 结尾以空白分隔  三 此时我们执行加载 D:>sqlldr userid=fancy/testpass control=result ctl log=resulthis outSQL*Loader: Release Production on 星期二 月 : : (c) Copyright Oracle Corporation   All rights reserved SQL*Loader :  在描述表RESULTXT时出现错误ORA : 对象 RESULTXT 不存在  提示出错 因为数据库没有对应的表   四 在数据库建立表   create table resultxt  (resultid varchar ( )    website varchar ( )    ipport varchar ( )    status varchar ( ))/  五 重新执行加载  D:>sqlldr userid=fancy/k i l l control=result ctl log=resulthis outSQL*Loader: Release Production on 星期二 月 : : (c) Copyright Oracle Corporation   All rights reserved 达到提交点 逻辑记录计数 达到提交点 逻辑记录计数   已经成功!我们可以通过日志文件来分析其过程 resulthis out内容如下 SQL*Loader: Release Production on 星期二 月 : : (c) Copyright Oracle Corporation   All rights reserved 控制文件: result ctl数据文件: result csv错误文件: result bad废弃文件: 未作指定: (可废弃所有记录)装载数: ALL跳过数: 允许的错误: 绑定数组: 行 最大 字节继续:    未作指定所用路径:       常规表RESULTXT已载入从每个逻辑记录插入选项对此表INSERT生效   列名                        位置      长度  中止 包装数据类型 RESULTID                            FIRST     *          CHARACTER            WEBSITE                              NEXT     *          CHARACTER            IPPORT                               NEXT     *          CHARACTER            STATUS                               NEXT     *  WHT      CHARACTER           

大量数据如何导入数据库 数据批量导入Oracle数据库

  表RESULTXT: 行载入成功由于数据错误 行没有载入 由于所有 WHEN 子句失败 行没有载入 由于所有字段都为空的 行没有载入

  为结合数组分配的空间:    字节( 行)除绑定数组外的内存空间分配:         字节跳过的逻辑记录总数:        读取的逻辑记录总数:        拒绝的逻辑记录总数:        废弃的逻辑记录总数:        从星期二 月  : : 开始运行在星期二 月  : : 处运行结束经过时间为: : : CPU 时间为: : : (可  六 并发操作  sqlldr userid=/ control=result ctl direct=true parallel=true   sqlldr userid=/ control=result ctl direct=true parallel=true   sqlldr userid=/ control=result ctl direct=true parallel=true    当加载大量数据时(大约超过 GB) 最好抑制日志的产生   SQL>ALTER TABLE RESULTXT nologging;    这样不产生REDO LOG 可以提高效率 然后在CONTROL文件中load data上面加一行 unrecoverable     此选项必须要与DIRECT共同应用   在并发操作时 ORACLE声称可以达到每小时处理 GB数据的能力!其实 估计能到 - G就算不错了 开始可用结构    相同的文件 但只有少量数据 成功后开始加载大量数据 这样可以避免时间的浪费

  我的示例一 在数据库建立表格weather如下 create table weather(outlook varchar( ) temperature float humidity float windy varchar( ) play varchar( ))二 在F盘建立两个文件 分别如下 # result ctl内容如下 load datainfile result csv into table weather(outlook char terminated by  temperature  char terminated by  humidity char terminated by  windy char terminated by  play char terminated by )

  # result csv内容如下 sunny FALSE nosunny TRUE noovercast FALSE yesrainy FALSE yesrainy FALSE yesrainy TRUE noovercast TRUE yessunny FALSE nosunny FALSE yesrainy FALSE yessunny TRUE yesovercast TRUE yesovercast FALSE yesrainy TRUE no三 命令行下执行F:>sqlldr userid=cqsb/ctbujx   control=result ctl

lishixinzhi/Article/program/Oracle/201311/18572  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码