五、演示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   --再次正常导入