Note: If external tables
are created with NOLOG then granting READ on the DIRECTORY object is
sufficient. If an external table is created without the NOLOG syntax then
both READ and WRITE must be granted to SELECT from it.
Prior to version 10g, external tables were READ ONLY. Insert, update, and delete could not be performed. Starting with version Oracle Database 10g, external tables can be written to as well as read from. Thanks to "Kathryn" for this update/correction.
Actions As SYS
Related Catalog Objects
dba_external_tables
all_external_tables
user_external_tables
Related System Privileges
create table
create any table
drop any table
Actions As SYS
Create Directory and
grant privileges
CREATE OR REPLACE DIRECTORY <name> AS <operating_system_path_and_directory>;
Records delimited by
RECORDS DELIMITED BY 0x'0A' demo submitted by Tom Burger of Exan Software
A comma delimited flat file is export from a UNIX database and
transferred for loading into a Windows based Oracle database. The lines are terminated with 0x0A and not the 0x0A 0x0D pair for DOS/Windows. The
fields are randomly double quoted, and some contain commas internal to the field's data like this:
100001,"7123 HIGHLAND DR","03/28/1965"," Mercer
Island, WA 98040","Morgan,
Dan A", "","","63034630752",
14,1,"F","T","06/28/2000","",0,"","01/01/1999","N",
"01/01/1999",""
100020,"5432 SOUTH 28TH ST","01/01/1951"," Mercer
Island, WA 98040", "Burger,Tom",
"","2566400","ZPW345070938",64,1,"M","B","02/23/2000","",0,"",
"12/31/1799","P","12/31/1979",""
The external file definition to load this data is:
CREATETABLE some_data (
ACCOUNT_NUM VARCHAR2(10),
ADDRESS VARCHAR2(30),
BIRTH_DATE VARCHAR2(10),
CITY_STATE_ZIP VARCHAR2(40),
NAME
VARCHAR2(30),
EMPLOYER_NAME VARCHAR2(30),
GROUP_NAME VARCHAR2(30),
ID_NO VARCHAR2(50),
PLAN_NO VARCHAR2(50),
VAR_REC VARCHAR2(50),
SEX
VARCHAR2(2),
TYPE
VARCHAR2(10),
UPDATE_DATE VARCHAR2(10),
EXD_ID VARCHAR2(30),
PCP
VARCHAR2(30),
PCP_EFFECT VARCHAR2(30),
CANCEL_DATE VARCHAR2(10),
COV_DEP VARCHAR2(30),
EFFECT_DATE VARCHAR2(10),
ADDL_INFO VARCHAR2(50))
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ext
ACCESS PARAMETERS
(RECORDS DELIMITED BY 0x'0A'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL)
LOCATION ('UNIX_DATA.DAT'))
REJECT LIMIT unlimited;
desc some_data
set linesize 121
col account_num format a10
col address format a20
col birth_date format a20
col city_state_zip format a20
col name format a20
SELECT account_num, address, birth_date, city_state_zip, name FROM some_data;
This eliminates the loader error of seeing the file as one single record
that exceeds the half MB limit and fields like "Doe,Jane R" are interpreted as a single field. This is from a real life situation I was
working on today. All of the data in the example is, of course, altered to privacy.