Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Chella.

Asked: July 09, 2001 - 10:22 am UTC

Last updated: September 09, 2005 - 9:09 pm UTC

Version: 8i

Viewed 1000+ times

You Asked

I am receiving data from an external source on a daily basis and then I have to upload the data into Oracle table. I can do this via a Control file but the problem is the INFILE name is not fixed and hence I am unable to specify INFILE 'filename'. The only way I can identify the filename is by looking at the date in the Windows Explorer. Is there a way to achieve what I want to do ? TIA

and Tom said...

You can use the DATA= command line parameter instead of INFILE= and if the file follows some naming convention, you could use the command:

for %f in ( *.* ) do sqlldr userid=user/pw control=control.ctl data=%f

to load it (where *.* of course is a wildcard that id's your specific file).

followup to comment one

Sorry it was not clear.

Instead of

LOAD DATA
INFILE 'c:\bsp\stmt.txt'
APPEND
INTO TABLE tblMailboxData
....

You will have

LOAD DATA
APPEND
INTO TABLE tblMailboxData
....

(no infile statment). Instead, you will use DATA= on the command line to sqlldr:

sqlldr userid=x/y control=c.ctl DATA=c:\bsp\stmt.txt


Now, if your filename is always CC*.001 and you want to load ALL of the CC*.001 files in a directory, the Windows command:


for %f in ( CC*.001 ) do sqlldr userid=user/pw control=control.ctl data=%f

will do that for you.



Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Identifying Data file

Chella, July 10, 2001 - 6:37 am UTC

The answer was helpful however, I am performing the upload using a control file which looks like;

LOAD DATA
INFILE 'c:\bsp\stmt.txt'
APPEND
INTO TABLE tblMailboxData
(
RecID SEQUENCE(MAX,1), -- To create a unique row id. Is this the correct syntax ?
CustSortCode POSITION(1:6),
CustAcNumber POSITION(7:14),
TransCode POSITION(16:17),
RemSortCode POSITION(18:23)
)

My data file name starts with 'cc', file extension is '001'. How do I replace the DATA= with INFILE ? Could you give me the correct syntax or point me to some materials ? Ta

Identifying Data file

Oliver DommackThoms, September 13, 2002 - 4:37 am UTC

Good Example, it even helps on those 'batch' Jobs where you don't know what files you get maybe via ftp.

I'm having an problem that's connected:
My files are deleted after insertion. In order to trace back where the data came from, I need the filename stored in the db as well!

Currently I'm woring with the .ctl as a variable in a Shell Skript which replaces the filename for the INFILE statement and as a CONSTANT for the db-input. That does solve my problem but is quite unaesthetic. ;-))
Is there a System/SQL Loader/Oracle variable where I can get the filename from if the Skript would instead simply execute a static .ctl with the DATA= parameter????

Tom Kyte
September 14, 2002 - 1:39 pm UTC

The shell replacement is the way to accomplish it. write the control file based on the filename and run it. Unaesthetic or not, its the way to get it done.

Identifying Data file

Kevin, September 08, 2005 - 8:24 pm UTC

Regarding, "write the control file based on the filename and run it",

In a production environment the user running the job doesn't have the privilege to be able to write out a control file on the fly.

What is the way to sqlload the name of the file being sqlloaded for a cron job or operator?

Tom Kyte
September 08, 2005 - 8:39 pm UTC

In a production environment the user running the job doesn't have the privilege
to be able to write out a control file on the fly.


why not?

that cron job can certainly write out the control file.

the operator can run a script that can certainly write out the control file.

that end user can certainly write out that control file.

why not?

Identifying Data file

Kevin, September 09, 2005 - 9:25 am UTC

The production directory where the control files are kept is owned by root and the group is a group that the cron user & operators don't belong to, and has read privilege for public:
drwxrwxr-x root qa


Tom Kyte
September 09, 2005 - 9:36 am UTC

so?

you would be writing the control file to /tmp or something and using it (it is a one time use control file)

Identifying Data file

Kevin, September 09, 2005 - 8:50 pm UTC

A wrapper script to sqlldr is used, which looks for the control file in that particular directory.

Tom Kyte
September 09, 2005 - 9:09 pm UTC

that means your process needs to change?