ORACLE-SQLLOAD import external data Detailed

Today, companies need to import some data from external text into the database. People here the relevant steps and pay attention to local records, the need for a reference to learn! The environment here is the database in the windows, linux or other databases the same way!

1. Preparation: Create a table structure need to import data, if you already have the relevant table, omit this step!

SQL> create table test
  2  (
  3    host          VARCHAR2(30),
  4    user_name VARCHAR2(30),
  5    ip_address      VARCHAR2(15),
  6    pass            VARCHAR2(4) default 'no' not null,
  7    judge           NUMBER default 0 not null,
  8    endtime         DATE
  9  );

Table has been created.

2, write sqlload import control file data, control files as tested here, may need to add the relevant control parameters according to their test, then copy the file can be saved as a txt!

LOAD DATA
INFILE 'd:\data.txt'
INTO TABLE test
TRUNCATE
fields terminated by ','
trailing nullcols 
(HOST,USER_NAME,IP_AddrESS,PASS,JUDge,endTIME)

There are other control file parameters, according to their own needs and adjust the test:

Attached part of the control parameters: the specific use of an official document shall prevail

The OPTIONS (Skip = . 1 , rows = 128 )     - sqlldr command option displayed can be written to this side, Skip = . 1 for the first row of data skipping
 the LOAD the DATA 
INFILE " users_data.csv "       - Specifies the external data file, data may be files in different formats, such as csv, txt support can write 
                   multiple INFILE
" another_data_file.csv " specifies a plurality of data files TRUNCATE    - the type of operation, with a truncate table to clear the records of the original table, as the case may whether the original data in the table clearly requires the INTO tABLE Users    - to insert record table Fields terminated by " , "   - with each row of data recording " , " separated OPTIONALLY ENCLOSED by '" ' - each data field with the ' ' ' double quotes framed, such fields have " , " separator when trailing NULLCOLS - when the corresponding field of the table is not allowed to be null value ( virtual_column the FILLER, - this It is a dummy field, used to skip from the PL / generated SQL Developer first column number user_id Number, - field may specify the type or types that are CHARACTER, log file display USER_NAME, LOGIN_TIMES, LAST_LOGIN DATE " YYYY-the MM-DD HH24: MI: the SS " - Specifies the format accepted date, quite a TO_DATE () function converts ) ------------------ -------------------------------------------------- ------------------------- INSERT - the default mode, the data load required initially empty tables the append - append a new record in the table the replace - delete old records (with the Delete from the Table statement), replaced by a new record of loading TRUNCATE - delete old records (with a truncate table statement), replaced by a new record of loading

 

3, create data to be imported, note that the data table structure and format must correspond exactly, or the import failed! Test data are as follows: the final parts of the data field is empty, the control file need to add trailing nullcols parameters!

ttt,SCOTT,192.168.1.111,yes,1,
qq,JACK,192.168.1.20,no,1,
YY,TOM,192.168.1.20,no,1,
WEB1,HAHA,192.168.1.1,no,1,
XXX,ROBIN,111.111.111.111,no,1,08-AUG-08
DB2,LUCY,192.168.10.10,no,1,
ORACLE,LILY,222.222.222.222,no,1,
WORKGROUP,DENNIS,133.133.133.133,no,0,08-AUG-08
DCR,CANDY,192.168.100.10,no,1,
T3,FLY,192.168.10.33,no,1,
T1,LINDA,192.168.10.200,no,1,08-AUG-08
T2,LILEI,192.168.100.31,no,1,08-AUG-08
You need to install the file

4, import data - also related to the import control parameters

Attaching portion import parameters: parameters can then view the command line input sqlldr

C:\Documents and Settings\Administrator>sqlldr

SQL * Loader: Release 11.2.0.1.0 - Production on Wednesday February 27 2013 17:13:24

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

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

Valid keywords:

    userid - ORACLE username / password
   control - control file name
       log - log file name
       bad - the error file
      data - data file name
   discard - discard the file name
discardmax - discarded allowed number of files (default all )
      skip - the number of logical records to skip (default 0)
      load - the number of the logical record to be loaded (all default)
    errors - the number of errors permitted (default 50)
      rows - conventional path bind array number of lines between the data storage or direct path
               (default: conventional path 64, all of the direct path)
  bindsize - conventional path bind array size (in bytes) (default 256000)
    Silent - during operation hidden message ( title, feedback, errors, waste, partition)
    direct - using the direct path (default FALSE)
   parfile - parameter file: file contains the name of the parameter description of
  parallel - to perform parallel load (default FALSE)
      file - from the following objects file allocation area
skip_unusable_indexes - Disable / Enable the use of useless index or index partition (default FALSE)
skip_index_maintenance - no maintenance of the index, the index will be affected labeled as useless (default FALSE)

commit_discontinued - line (default FALSE) when submitting loaded interrupt loaded
  readsize - read buffer size (default 1048576)
external_table - using external loading tables; NOT_USED, GENERATE_ONLY, EXECUTE (default NO
T_USED)
columnarrayrows - the number of rows direct path column array (default 5000)
streamsize - direct path stream buffer size (in bytes) (default 256000)
multithreading - use multithreading in a direct path
 resumable - current may be enabled or disabled restore session (default FALSE)
RESUMABLE_NAME - help text string to identify recoverable statement
resumable_timeout - RESUMABLE waiting time (in seconds) (default 7200)
date_cache - date translation cache size (in entries dollars) (default 1000)
suspended load (default FALSE) when the index any errors - no_index_errors

 

The following commands: control = path Specifies the control file and import log = log files bad = error data = data file

Start the import:

C:\Documents and Settings\Administrator>sqlldr scott/tiger control=d:\sqlload.txt log=d:\loadlog.txt bad=d:\bad.txt data=d:\data.txt
SQL*Loader: Release 11.2.0.1.0 - Production on 星期三 2月 27 17:06:52 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count of 12

After successful import see the results:

C:\Documents and Settings\Administrator>sqlplus scott/tiger

SQL * Plus: Release 11.2.0.1.0 Production on Wednesday February 27 2013 17:07:05

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

连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from test;

HOST       USER_NAME  IP_ADDRESS                     PASS          JUDGE ENDTIME
----------      ----------      ------------------------------         --------           ---------- --------------
ttt             SCOTT      192.168.1.111                  yes               1
qq             JACK         192.168.1.20                    no                1
YY            TOM          192.168.1.20                    no                1
WEB1        HAHA        192.168.1.1                     no                1
DB2           LUCY         192.168.10.10                 no                1
ORACLE     LILY           222.222.222.222             no                1
DCR          CANDY       192.168.100.10                no                1
T3            FLY           192.168.10.33                  no                1

8 selected row.

Result is clearly inconsistent with the data file, the last data field has a value of no import! This is not the final desired result! To be sure the data has been imported, a table showing target and control files no problem!

It should be the question format data files! Note that the data file final field is the date data type. View existing date is not a database file type does not support data representation format

SQL> select sysdate from dual;

SYSDATE
--------------
 27 - Feb - 13

Obviously we date and inconsistent data file is displayed, and the Chinese, where the data can last field of data files and databases into the same format, it can also make changes to the format and language of the database,

Because this test system is windows error appears in linux can be avoided!

If linux can try the following steps to resolve:

alter system set nls_date_format='DD-MON-RR';

alter system set nls_language = american scope = spfile; ------------ obtained restart the database

Because here is the windows, here is not to change the language and restart the database, data files directly to make changes to the data file modified as follows

 

ttt,SCOTT,192.168.1.111,yes,1,
qq,JACK,192.168.1.20,no,1,
YY,TOM,192.168.1.20,no,1,
WEB1,HAHA,192.168.1.1,no,1,
XXX,ROBIN,111.111.111.111,no,1,08-5月 -08
DB2,LUCY,192.168.10.10,no,1,
ORACLE,LILY,222.222.222.222,no,1,
WORKGROUP, DENNIS, 133.133 . 133.133 , No, 0 , 08 - 5 May - 08 
DCR, CANDY, 192.168 . 100.10 , No, 1 ,
T3,FLY,192.168.10.33,no,1,
T1, LINDA, 192.168 . 10.200 , No, 1 , 08 - 5 May - 08 
T2, LILEI, 192.168 . 100.31 , No, 1 , 08 - 5 May - 08

Imported once again, after the import view results

 

C:\Documents and Settings\Administrator>sqlldr scott/tiger control=d:\sqlload.txt log=d:\loadlog.txt bad=d:\bad.txt data=d:\data.txt

SQL * Loader: Release 11.2.0.1.0 - Production on Wednesday February 27 2013 17:48:44

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count of 12

 

C:\Documents and Settings\Administrator>sqlplus scott/tiger

SQL * Plus: Release 11.2.0.1.0 Production on Wednesday February 27 2013 17:49:21

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


连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> col host for a10
SQL> col user_name for a15
SQL> select * from test;

HOST           USER_NAME       IP_ADDRESS                     PASS          JUDGE ENDTIME
----------        --------------- ------------------------------                --------         ---------- --------------
ttt               SCOTT           192.168.1.111                      yes               1
qq               JACK            192.168.1.20                          no                1
YY              TOM             192.168.1.20                          no                1
WEB1          HAHA            192.168.1.1                           no                1
XXX             ROBIN           111.111.111.111                    no                1 08-5月 -08
DB2             LUCY            192.168.10.10                        no                1
LILY 222.222.222.222 No ORACLE 1
WORKGROUP DENNIS 133.133.133.133 No 0 08- 5 May -08
DCR CANDY 192.168.100.10 No 1
T3 FLY 192.168.10.33 No 1
T1 LINDA 192.168.10.200 No 1 08- 5 May -08
T2 LILEI 192.168 .100.31 no 1 08- 5 May -08

We have selected 12 lines.

Back to normal: data and data files exactly the same! This entire data import is complete! Where the main attention is the establishment of a data file, and confirm the structure as well as separate tables correspond!

Guess you like

Origin www.cnblogs.com/vmsysjack/p/12158687.html