Sponsored Content
Top Forums Shell Programming and Scripting How to read a dynamically changing file and load into Oracle? Post 302074497 by tmarikle on Tuesday 23rd of May 2006 03:46:31 PM
Old 05-23-2006
Quote:
Originally Posted by madhunk
Thank you tmarikle...

I did not quite understand what exactly you meant by it...

Yes...It is a tab delimited file. But the problem is that if there are no values in the rest of the columns, they are not filled with spaces or tabs...

Row1: A B C D E F G H
Row2: A B C D
Row3: A B

I am absolutely not sure how I can do this...
Both sqlldr and external tables can process data in the format that you have described. I'll edit this post with some examples shortly.

Additional info:

Here is how you can define an external table using another table and a sqlldr control file to start with.

1) Create your table:

CREATE TABLE my_external_table (
my_key_no VARCHAR2(45)
,load_date DATE
,col_a VARCHAR2(30)
,col_b VARCHAR2(30)
,col_c VARCHAR2(30)
,col_d VARCHAR2(30)
,col_e VARCHAR2(30)
,col_f VARCHAR2(30)
)

2) Create a control file for sqlldr that allows for "missing" columns as per your requirement.

LOAD DATA

INTO TABLE "MY_EXTERNAL_TABLE"
APPEND

FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' AND '"'
TRAILING NULLCOLS

(
my_key_no "SUBSTRB(:my_key_no, 1, 45)"
,load_date "TO_DATE(:load_date, 'YYYYMMDD')"
,col_a "SUBSTRB(:col_a , 1, 30)"
,col_b "SUBSTRB(:col_a , 1, 30)"
,col_c "SUBSTRB(:col_a , 1, 30)"
,col_d "SUBSTRB(:col_a , 1, 30)"
,col_e "SUBSTRB(:col_a , 1, 30)"
,col_f "SUBSTRB(:col_a , 1, 30)"
)

3) Use sqlldr to define a comperable external table definition.

sqlldr user/pwd test.ctl external_table=generate_only

4) The resulting log file contains the external table DDL and examples on how to use it.

CREATE TABLE "SYS_SQLLDR_X_EXT_MY_EXTERNAL_T"
(
"MY_KEY_NO" VARCHAR(255),
"LOAD_DATE" VARCHAR(255),
"COL_A" VARCHAR(255),
"COL_B" VARCHAR(255),
"COL_C" VARCHAR(255),
"COL_D" VARCHAR(255),
"COL_E" VARCHAR(255),
"COL_F" VARCHAR(255)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET WE8MSWIN1252
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'test.bad'
LOGFILE 'test.log_xt'
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"MY_KEY_NO" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"LOAD_DATE" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"COL_A" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"COL_B" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"COL_C" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"COL_D" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"COL_E" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """ ,
"COL_F" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' AND """
)
)
location
(
'test.dat'
)
)REJECT LIMIT UNLIMITED

At any rate, you can read up on external tables at asktom.oracle.com.

Last edited by tmarikle; 05-23-2006 at 05:08 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (4 Replies)
Discussion started by: handynas
4 Replies

2. Shell Programming and Scripting

load a data from text file into a oracle table

Hi all, I have a data like, 0,R001,2,D this wants to be loaded into a oracle database table. Pl let me know how this has to be done. Thanks in advance (2 Replies)
Discussion started by: raji35
2 Replies

3. Shell Programming and Scripting

Load data from a flat file to oracle.

I have a flat file with records like Header 123 James Williams Finance2000 124 Pete Pete HR 1500 125 PatrickHeather Engg 3000 Footer The structure is: Eno:4 characters Name:8 characters Surname : 9 characters Dept:7 characters Sal:4characters These are sample... (1 Reply)
Discussion started by: Shivdatta
1 Replies

4. Shell Programming and Scripting

Can't load external file from unix into Oracle DB

Hi all, I'm traying to run a script on Unix with in it sql +. In this script I want to load a externall file that stand on my unix system into a tmp table of a oracle db, but for some reason it won't work. Find below the script. #!/bin/ksh ORACLE_SID=db1... (7 Replies)
Discussion started by: Tuut-Tuut
7 Replies

5. Shell Programming and Scripting

Check value of load balance dynamically

Hi All, I want to check load balance(or CPU utilzation) on server dynamically based on that value i want to perform some operation . Means if load balance is <10 then start server . Am using prstat -a 1 commadn it is listing CPU utilzation/load balancing dynamically .. How to take this... (7 Replies)
Discussion started by: vivek1489
7 Replies

6. UNIX for Dummies Questions & Answers

Read a file dynamically

Hi my requriment is read the file name dynamically my code is #!/bin/sh file="/c/work/loan/" Header_Trailer_move() { sed '1d;$d' $file| cat >sam.txt } Header_Trailer_move in above given path my list of files or there i have to read file dyanamically when i entered particular file name... (2 Replies)
Discussion started by: sgoud
2 Replies

7. Shell Programming and Scripting

How to read a dynamically changing file

I want to read a constantly changing file and do some operation on text found in that file. Actually that is log file of linux system and whenever i find a matching string in that file i want to create a text file with timestamp. is it possible to read that file? here is sample output of log... (7 Replies)
Discussion started by: kashif.live
7 Replies

8. Shell Programming and Scripting

Script to load daily average I/O stats from a .ksh file into Oracle db

Hi can anyone help me with a script to load output of the .ksh file into an Oracle database. I have attached sample output of the information that i need to load to the database (2 Replies)
Discussion started by: LucyYani
2 Replies

9. Shell Programming and Scripting

Parameterizing to dynamically generate the extract file from Oracle table using Shell Script

I have below 2 requirements for parameterize the generate the extract file from Oracle table using Shell Script. Could you please help me by modifying the script and show me how to execute it. First Requirement: I have a requirement where I need to parameterize to generate one... (0 Replies)
Discussion started by: hareshvikram
0 Replies

10. Shell Programming and Scripting

Script to load XML file to Oracle table

Experts. I have created a oracle table as below. create table xml_tab ( File_No number , File_content Varchar2(2000), file_type xmltype ); Daily we are receiving many XML files as below. here is our sample xml file. File1 : (7 Replies)
Discussion started by: vasuvv
7 Replies
All times are GMT -4. The time now is 03:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy