Sqlldr loads data into the database. The data in the External table is based on the operating system file, and the real data is not saved to the database, which is in the operating system file. Therefore, the data in the External table can only be selected. External tables can basically replace sqlldr. In the following three cases, choose sqlldr instead of External table:
1. Data must be loaded through the network, that is, the input file is not on the database server.
2. Multiple users must concurrently use the same external table to process different input files.
3. the LOB type must be used. External tables do not support logs.
Use sqlldr to generate external table scripts
- [Oracle @ linux sqlldr] $ pwd
- /U01/sqlldr
- [Oracle @ linux sqlldr] $ cat demo1.ctl
- LOADDATA
- INFILE *
- INTO TABLEDEPT
- FIELDS TERMINATEDBY ','
- (DEPTNO, DNAME, LOC)
- BEGINDATA
- 10, Sales, Virginia
- 20, Accounting, Virginia
- 30, Consulting, Virginia
- 40, Finance, Virginia
- ABC, XYZ, Hello
- [Oracle @ linux sqlldr] $ sqlldr ing/ing demo1.ctl external_table = generate_only
- SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 21:59:06 2011
- Copyright (c) 1982,200 7, Oracle.AllRights reserved.
View the generated log file
- [Oracle @ linux sqlldr] $ pwd
- /U01/sqlldr
- [Oracle @ linux sqlldr] $ cat demo1.log
- SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 21:59:06 2011
- Copyright (c) 1982,200 7, Oracle.AllRights reserved.
- Control File: demo1.ctl
- Data File: demo1.ctl
- Error file: demo1.bad
- Obsolete file: Not specified
- (All records can be discarded)
- Number of objects to be loaded:ALL
- Number of to be skipped: 0
- Allowed error: 50
- Continue: Unspecified
- Path used: External table
- Table DEPT, loaded from each logical record
- Insert option for this tableINSERTEffective
- Column name location length abort packaging Data Type
- --------------------------------------------------------------------------
- DEPTNOFIRST*,CHARACTER
- DNAMENEXT*,CHARACTER
- LOCNEXT*,CHARACTER
- File needsCREATEDIRECTORY statements
- ------------------------------------------------------------------------
- CREATEDIRECTORY SYS_SQLLDR_XT_TMPDIR_00000AS '/U01/sqlldr'
- -- Connect sqlldr to the database and query the data dictionary. If no appropriate directory is found, create a SYS_SQLLDR_XT_TMPDIR_00000 directory.
- Used for external tablesCREATE TABLEStatement:
- ------------------------------------------------------------------------
- CREATE TABLE "SYS_SQLLDR_X_EXT_DEPT"-- Create a table SYS_SQLLDR_X_EXT_DEPT
- (
- "DEPTNO"NUMBER (10 ),
- "DNAME"VARCHAR2 (20 ),
- "LOC"VARCHAR2 (20)
- )
- ORGANIZATION external-- Indicates that this is not a common table, but an External table.
- (
- TYPE oracle_loader-- Load the data type. In addition, there is a 10 Gb ORACLE_DATAPUMP that can be used to load or unload data.
- DEFAULTDIRECTORY SYS_SQLLDR_XT_TMPDIR_00000-- Use the previously created directory SYS_SQLLDR_XT_TMPDIR_00000
- ACCESS PARAMETERS
- (
- RECORDS DELIMITEDBYNewline characterset ZHS16GBK-- The Record ends with a line break by default.
- BADFILE'Sys _ SQLLDR_XT_TMPDIR_00000':'Demo1. bad'-- Record a bad file in the newly created directory. Records that cannot be loaded will be recorded in this file.
- LOGFILE'Demo1. log_xt'-- Log file.
- READSIZE 1048576-- Size of the cache for loading data. 1024*1024 = 1048576
- SKIP 6-- Skip the first six rows without loading, because the first six rows are information of the sqlldr control file.
- FIELDS TERMINATEDBY ","LDRTRIM-- Data is separated by commas (,). LDRTRIM indicates removing the leading and trailing spaces.
- REJECTROWS WITH ALL NULLFIELDS-- External tables record empty rows in bad files without loading these rows.
- (
- "DEPTNO" CHAR(255)
- TERMINATEDBY ",",
- "DNAME" CHAR(255)
- TERMINATEDBY ",",
- "LOC" CHAR(255)
- TERMINATEDBY ","
- )
- )
- Location
- (
- 'Demo1. ctl'-- Tells the name of the file loaded by oracle.
- )
- ) REJECT LIMIT UNLIMITED
- Used to load internal tablesINSERTStatement:
- ------------------------------------------------------------------------
- INSERT/* + Append */INTODEPT-- Load data directly from the External table.
- (
- DEPTNO,
- DNAME,
- LOC
- )
- SELECT
- "DEPTNO",
- "DNAME",
- "LOC"
- FROM "SYS_SQLLDR_X_EXT_DEPT"
- The statement used to clear the object created by the previous statement:
- ------------------------------------------------------------------------
- DROP TABLE "SYS_SQLLDR_X_EXT_DEPT"-- Delete an External table.
- DROPDIRECTORY SYS_SQLLDR_XT_TMPDIR_00000-- Delete a directory.
- Starting from 21:59:06, January 1, 2011, Tuesday
- The operation ended at 21:59:06, January 1, October 04, 2011.
- Elapsed time: 00: 00: 00.14
- CPU time: 00: 00: 00.04