你好,游客 登录 注册 搜索
背景:
阅读新闻

SQL*Loader使用方法

[日期:2012-01-18] 来源:Linux社区  作者:robinson_0612 [字体:大 中 小]

四、数据文件装载方式   

    1.传统路径导入

        使用生成SQL Insert语句来处理源数据,并且通过commit提交保存数据。每次数据导入将产生一些事务

        在插入数据时寻找可用数据块,然后将数据填充到数据块

        在插入到分区表的单个分区时使用下面的语法

            INSERT INTO TABLE T PARTITION (P) VALUES ...

        基于多cpu系统使用多个装载会话执行并发。即将数据文件分割为多个来装载

       

    2.直接路径导入

        直接将数据写到Oracle数据文件,并更所使用块的高水位线标记来保存数据

        支持数据的并行导入

        直接路径导入期间,数据转换发生在客户端而非服务器端。即位于服务器端参数文件中NLS参数不会被使用

            可以通过在控制文件中设置NLS参数或设置服务器端合适的环境变量,如下面的例子

            HIREDATE DATE 'YYYYMMDD'               --为控制文件中的HIREDATE指定格式

            % export NLS_DATE_FORMAT='YYYYMMDD'    --在服务器端设定NLS_DATE_FORMAT

        直接路径装载单个分区或子分区,装载期间的其它分区可以执行DML操作

            LOAD INTO TABLE T PARTITION (P) VALUES ...

            LOAD INTO TABLE T SUBPARTITION (P) VALUES ...

        使用直接路径装载时,需要指定DIRECT=true

        支持两种不同的并发

            1.同时装载到分区表表的不同分区或同时装载到不同的表

            2.分成多个服务器装载到分区表的单个分区或单个表,最后将装载的临时段合并保存到分区或表

   

    3.两者对比(下面描述中传统导入方式称为前者,直接导入方式称为后者)

        a.前者使用commit来保存数据,后者更新高水位线标记保存数据

        b.前者产生redo记录,后者基于特定的条件产生redo记录

        c.前者强制所有的约束,后者仅仅强制primary key,unique,not null约束

        d.前者将触发insert触发器,后者不会触发insert触发器

        e.前者支持簇表,后者不支持簇表

        f.前者插入数据时其它用户可以DML表,后者则不行

       

五、演示SQL*Loader 

    1.SQL*Loader可执行程序(sqlldr)所在的位置

        [oracle@oradb ~]$ ls -lh $ORACLE_HOME/bin/sql*

        -rwxr-x--x 1 oracle oinstall 634K Sep 13 20:01 /u01/app/oracle/10g/bin/sqlldr

 

    2.查看sqlldr的帮助信息,

        [oracle@oradb ~]$ sqlldr

 

        SQL*Loader: Release 10.2.0.1.0 - Production on Thu Sep 23 10:38:31 2010

 

        Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

 

        Usage: SQLLDR keyword=value [,keyword=value,...]

 

        Valid Keywords:

 

            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          (Default all)

              skip -- number of logical records to skip    (Default 0)

              load -- number of logical records to load    (Default all)

            errors -- number of errors to allow            (Default 50)

              rows -- number of rows in conventional path bind array or between direct path data saves

                       (Default: Conventional path 64, Direct path all)

          bindsize -- size of conventional path bind array in bytes  (Default 256000)

            silent -- suppress messages during run (header,feedback,errors,discards,partitions)

            direct -- use direct path                      (Default FALSE)

           parfile -- parameter file: name of file that contains parameter specifications

          parallel -- do parallel load                     (Default FALSE)

              file -- file to allocate extents from     

        skip_unusable_indexes -- disallow/allow unusable indexes or index partitions  (Default FALSE)

        skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable  (Default FALSE)

        commit_discontinued -- commit loaded rows when load is discontinued  (Default FALSE)

          readsize -- size of read buffer                  (Default 1048576)

        external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE  (Default NOT_USED)

        columnarrayrows -- number of rows for direct path column array  (Default 5000)

        streamsize -- size of direct path stream buffer in bytes  (Default 256000)

        multithreading -- use multithreading in direct path 

         resumable -- enable or disable resumable for current session  (Default FALSE)

        resumable_name -- text string to help identify resumable statement

        resumable_timeout -- wait time (in seconds) for RESUMABLE  (Default 7200)

        date_cache -- size (in entries) of date conversion cache  (Default 1000)

 

        PLEASE NOTE: Command-line parameters may be specified either by

        position or by keywords.  An example of the former case is 'sqlldr

        scott/tiger foo'; an example of the latter is 'sqlldr control=foo

        userid=scott/tiger'.  One may specify parameters by position before

        but not after parameters specified by keywords.  For example,

        'sqlldr scott/tiger control=foo logfile=log' is allowed, but

        'sqlldr scott/tiger control=foo log' is not, even though the

        position of the parameter 'log' is correct.

       

    3.将数据文件和控制文件组合在一起

        [oracle@oradb ~]$ cat sqlldr_demo/demo1.ctl 

        LOAD DATA

        INFILE *

        INTO TABLE DEPT

        FIELDS TERMINATED BY ','

        (DEPTNO, DNAME, LOC )

        BEGINDATA

        10,Sales,Virginia

        20,Accounting,Virginia

        30,Consulting,Virginia

        40,Finance,Virginia

               

        SQL> show user;

        USER is "ROBINSON"

        SQL> create table dept

          2  (deptno number(2) constraint dept_pk primary key,

          3   dname varchar2(20),

          4   loc varchar2(20));

 

        Table created.

 

        [oracle@oradb sqlldr_demo]$ sqlldr robinson/robinson control=demo1.ctl

 

        SQL*Loader: Release 10.2.0.1.0 - Production on Thu Sep 23 11:29:34 2010

 

        Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

        Commit point reached - logical record count 4      

 

        SQL> select * from dept;

 

            DEPTNO DNAME                LOC

        ---------- -------------------- --------------------

                10 Sales                Virginia

                20 Accounting           Virginia

                30 Consulting           Virginia

                40 Finance              Virginia

 

    4.将数据文件和控制文件分离实现数据装载

        [oracle@oradb sqlldr_demo]$ cat demo1.ctl demo1.data  --查看分离后两者的内容

        LOAD DATA

        INFILE demo1.data

        INTO TABLE DEPT

        FIELDS TERMINATED BY ','

        (DEPTNO, DNAME, LOC )

 

        10,Sales,Virginia

        20,Accounting,Virginia

        30,Consulting,Virginia

        40,Finance,Virginia    

 

        [oracle@oradb sqlldr_demo]$ sqlldr robinson/robinson control=demo1.ctl log=demo1.log

 

        SQL*Loader: Release 10.2.0.1.0 - Production on Thu Sep 23 12:21:35 2010

 

        Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

        SQL*Loader-601: For INSERT option, table must be empty.  Error on table DEPT

 

        SQL> truncate table dept;   --收到了SQL*Loader-601错误提示,清空原表

 

        [oracle@oradb sqlldr_demo]$ sqlldr robinson/robinson control=demo1.ctl log=demo1.log

 

        SQL*Loader: Release 10.2.0.1.0 - Production on Thu Sep 23 12:22:39 2010

 

        Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

        Commit point reached - logical record count 4   --再次正常导入

linux
相关资讯       Oracle基础教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款