| Loading data from flat file into table without SQL Loader [message #27159] |
Thu, 28 August 2003 01:46  |
Sunil
Messages: 132 Registered: September 1999
|
Senior Member |
|
|
Hi,
I need to load data from a flat file to a table without using sql loader. How is it possible and what would the speed and performance be like in comparision to SQL Loader. Could anybody give me an example of the type of script that needs to be done for the same (i.w without SQL loader, what would the PL/SQL code be like)
Thanks
|
|
|
|
| Re: Loading data from flat file into table without SQL Loader [message #27165 is a reply to message #27159] |
Thu, 28 August 2003 06:29   |
Mark
Messages: 284 Registered: July 1998
|
Senior Member |
|
|
Try an external table, before you can create an external table, you need to create an Oracle directory object that points to the operating system directory in which your text file resides.
CONNECT sys/manager AS SYSDBA;
CREATE OR REPLACE DIRECTORY dat_dir AS 'C:OradataData';
CREATE OR REPLACE DIRECTORY log_dir AS 'C:OradataLog';
CREATE OR REPLACE DIRECTORY bad_dir AS 'C:OradataBad';
GRANT READ ON DIRECTORY dat_dir TO scott;
GRANT WRITE ON DIRECTORY log_dir TO scott;
GRANT WRITE ON DIRECTORY bad_dir TO scott;
external table:
CREATE TABLE address (id number,
house_num varchar2(20),
rcl_id NUMBER,
rna_id NUMBER,
xmin NUMBER,
ymin NUMBER
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY dat_dir
ACCESS PARAMETERS
(
records delimited by newline
badfile bad_dir:'address%a_%p.bad'
logfile log_dir:'address%a_%p.log'
fields terminated by ','
missing field values are null
( id,
house_num,
rcl_id,
rna_id,
xmin,
ymin
)
)
LOCATION ('address.dat')
)
PARALLEL 4
REJECT LIMIT UNLIMITED;
-----------------
Then you can use the Merge command to insert or update your production table.
MERGE INTO revenue dest
USING (SELECT id,
house_num,
rcl_id,
rna_id,
xmin,
ymin
FROM address) src
ON (dest.id = src.id)
WHEN MATCHED THEN
UPDATE SET dest.house_num = src.house_num,
dest.rcl_id=src.rcl_id,
dest.rna_id=src.rna_id,
dest.xmin=src.xmin,
dest.ymin=src.ymin
WHEN NOT MATCHED THEN
INSERT (id, house_num, rcl_id,rna_id,xmin,ymin)
VALUES (src.id, src.house_num, src.rcl_id,src.rna_id,src.xmin,src.ymin);
I set the degree of parallelism to four when you created the external table, the database will divide the file to be read by four processes running in parallel. This is good when you have millions... of records to load.
Good Luck
|
|
|
|
|
|
| Re: Loading data from flat file into table without SQL Loader [message #27176 is a reply to message #27172] |
Fri, 29 August 2003 09:36  |
 |
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
External tables are not avaiable in 8i.
the one workaroudn without using UTL_FILE or sql*loader is to use of OCI or perl.
90% of opensource users / developers find PERL to be the best text processing language.
you have to write a perl wrapper to parse the text file, strip the data and load into the oracle.
performance is "ok" in many cases ( we use it for BIOINFORMATICS). advantage is , with perl code, you can do any kind of processing with are not possible with sql*loader~
|
|
|
|