Anda di halaman 1dari 3

Subject:A working example for External Tables with VARIABLE records

  Doc ID:179325.1 Type:BULLETIN


  Modified Date:24-APR-2003 Status:PUBLISHED

PURPOSE
-------

This document provides a working example for External Table


with Variable record input.

SCOPE & APPLICATION


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

This article is intended for both Oracle Technical employees


and customers.

A WORKING EXAMPLE FOR VARIABLE RECORDS READ THROUGH EXTERNAL TABLES


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

1) The working example


======================

---------------------EXTTABVAR1.DAT <CUT HERE> ---------------------


21Alvin,Tolliver,1976,
19Kenneth,Baer,1963,
16Mary,Dube,1976,
---------------------<END> EXTTABVAR1.DAT --------------------------

Explanation for EXTTABVAR1.DAT:


21 for instance represents the length of 'Alvin,Tolliver,1976,'
which is 20 with the last termination character plus 1 implicit
New Line character.

---------------------EXTTABVAR2.DAT <CUT HERE> ---------------------


19Alvin,Tolliver,197617Kenneth,Baer,196314Mary,Dube,1976
---------------------<END> EXTTABVAR2.DAT --------------------------

Explanation for EXTTABVAR2.DAT:


19 is the length of the string 'Alvin,Tolliver,1976', no explicit
comma as string terminator, no implicit New Line Character.

---------------------EXTTABVAR.SQL <CUT HERE> ----------------------


set echo on;
connect / as sysdba;
create or replace directory scott_tmp as 'diskdir';
grant read,write on directory scott_tmp to scott;

connect scott/tiger;

DROP TABLE EXTTABVAR1;

CREATE TABLE EXTTABVAR1


(first_name CHAR(15),
last_name CHAR(20),
year_of_birth CHAR(4)
)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER DEFAULT DIRECTORY scott_tmp
ACCESS PARAMETERS
(RECORDS VARIABLE 2 FIELDS TERMINATED BY ","
(first_name,
last_name,
year_of_birth)
)
LOCATION ('exttabvar1.dat')
)
REJECT LIMIT UNLIMITED;
SELECT * from EXTTABVAR1;

DROP TABLE EXTTABVAR2;

CREATE TABLE EXTTABVAR2


(first_name CHAR(15),
last_name CHAR(20),
year_of_birth CHAR(4)
)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER DEFAULT DIRECTORY scott_tmp
ACCESS PARAMETERS
(RECORDS VARIABLE 2 FIELDS TERMINATED BY ","
(first_name,
last_name,
year_of_birth)
)
LOCATION ('exttabvar2.dat')
)
REJECT LIMIT UNLIMITED;
SELECT * FROM EXTTABVAR1;
----------------------<END> EXTTABVAR.SQL-------------------------

2) The errors that you might see


================================

The example for External Tables with Variable Size in the Utilities
Manual Chapter 12 does not work straight out of the book:

CREATE TABLE (first_name CHAR(15), last_name CHAR(20), year_of_birth CHAR(4))


ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (RECORDS VARIABLE 2 FIELDS TERMINATED BY ","
(first_name CHAR(7),
last_name CHAR(8),
year_of_birth CHAR(4))
LOCATION ('foo.dat'));

foo.dat
20Alvin,Tolliver,1976
18Kenneth,Baer,1963
15Mary,Dube,1973
You will receive these errors at different stages of the effort
to make it work (these errors are documented so that interested
parties can find this article):
Please note that defining a directory and granting access to it
is a prequisite to this exercise:
SQL> create or replace directory ext_tab_dir as '<diskdir>';
SQL> grant read,write on directory ext_tab_dir to scott;

On table creation:

ORA-00903: invalid table name


Reason: missing tablename
ORA-30648: missing LOCATION keyword
Reason: there is a parenthesis missing to close the RECORDS VARIABLE.

On select from table:

ORA-29913: error in executing ODCIEXTTABLEFETCH callout


ORA-30653: reject limit reached
ORA-06512: at "SYS.ORACLE_LOADER", line 14
ORA-06512: at line 1
Check <TABLE>_<PROCESS>.bad file. All records rejected
Check <TABLE>_<PROCESS>.LOG file.Contains:
KUP-04021: field formatting error for field YEAR_OF_BIRTH
KUP-04026: field too long for datatype
KUP-04101: record 1 rejected in file DISK$USER:[RROHR]foo.dat

Reason: the length for the records is wrong.

Note: the .BAD and the .LOG files are found in the directory that
you define as location for the external file and can provide more
help on what the problem is.

RELATED DOCUMENTS
-----------------
Note 150740.1 9i: External Tables Overview and Usage
Note 179516.1 A working example for External tables with the FIELDS
parameter on VARCHARC
Note 210510.1 Oracle9i SQL*Loader New Feature: The EXTERNAL_TABLE Command-
Line Parameter

Anda mungkin juga menyukai