Uploading Daily Files.
If you can load a file using SQLLDR you can now load the same file using external tables. Caveat - as long as the file is on the database server.
You will first need to prove that you can load the file to the database using SQLLDR.
Then, as DBA, create a directory in the database and grant read and write to your user. You need write access to the directory, because Oracle will update the logfile each time you 'load' the file. The logfile could in theory be placed in another 'writeable'
directory.
create or replace directory COMET_LOAD as '/app/toolkit/COMET';
grant read on directory COMET_LOAD to cometimport;
grant write on directory COMET_LOAD to cometimport;
Then using SQLLDR you can generate the commands to build your external table
SQLLDR .....all your commands...... EXTERNAL_TABLE=GENERATE_ONLY.
Opening up the logfile will reveal the create table command necessary to build an external table on the file mentioned in your SQLLDR statement.
CREATE TABLE COMETIMPORT.LINK_DYNAMIC_EXTERNAL
(
TOOLKIT_LINK_ID VARCHAR2(255 BYTE),
CONGESTIONPERCENT NUMBER,
CURRENTFLOW NUMBER,
AVERAGESPEED NUMBER,
LINKTRAVELTIME NUMBER,
LASTUPDATED DATE,
EXITBLOCKED NUMBER,
LINKSTATUS NUMBER,
JOURNEYCOUNT NUMBER,
TYPE_OF_DAY VARCHAR2(255 BYTE),
DAYSLICE VARCHAR2(255 BYTE),
TOOLKIT_TYPE_OF_DAY VARCHAR2(255 BYTE)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY COMET_LOAD
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'COMET_LOAD':'comet_bad_xt.bad'
LOGFILE 'COMET_LOAD':'comet_lg_xt.log'
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
TOOLKIT_LINK_ID CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
CONGESTIONPERCENT CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
CURRENTFLOW CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
AVERAGESPEED CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
LINKTRAVELTIME CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
LASTUPDATED CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS",
EXITBLOCKED CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
LINKSTATUS CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
JOURNEYCOUNT CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
TYPE_OF_DAY CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
DAYSLICE CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"',
TOOLKIT_TYPE_OF_DAY CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
)
)
LOCATION (COMET_LOAD:'linkdynamic20090121.csv')
)
REJECT LIMIT UNLIMITED
NOPARALLEL
NOMONITORING;
You can create the table without the file being present, querying it without the file present will generate an error.
Extracting the data is then done as an insert into...... select * from .... query
If you need to load another file, with a different name, you can perform an alter table command.
ALTER TABLE link_dynamic_external LOCATION ('linkdynamic20090101.csv');