Home » RDBMS Server » Server Utilities » Writting keyword to table
Writting keyword to table [message #180449] Mon, 03 July 2006 10:41 Go to next message
gconner1997
Messages: 10
Registered: July 2006
Location: New York
Junior Member
Hi,

Not sure how to describe this, so below my have redundant examples:

I'm trying to write the 'DATA' keyword contents into my table during the load.

My datafile is one column/field short. The last column in the table I want to load is myfilename. I use the trailing nullcols and wish to load that last column with the contents of the keywork DATA from the command line.

From the command line:
sqlldr <user/pwd@server> control=myctrl.ctl data="mydata.dat" log=....

What I want to do is pass the phrase "mydata.dat" to the control file into my table.

LOAD DATA
INFILE *
INTO TABLE emp
FIELDS TERMINATED BY ','
TRAILING NULLCOLS

(MYIDINFILE NULLIF (MYIDINFILE=BLANKS),
MYFILENAME "DATA"
)

I found a solution that suggests for instance
FILENAME "USER"

This works. I actually get my name in the field FILENAME during the load.

Logically I would think the line should be one of these:
myFileName "DATA"
myFileName "INFILE"
myFileName DATA
myFileName INFILE
myFileName "$4"
myFileName ":4"
myFileName "&4"
myFileName $4
myFileName :4
myFileName &4

but nothing works.
I know I can actually generate a constant from a pl/sql statement, or I can write a python script to append each line in the file I load with the name of the file,
but this would be so much easier if I could just capture the data on the command line.

Can this be done?
Thanks
--glenn


Re: Writting keyword to table [message #180450 is a reply to message #180449] Mon, 03 July 2006 10:50 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Not sure what you are trying to do.
Are you trying to load the input filename dynamically?
If so, you need a wrapper. Something like this
http://www.orafaq.com/forum/t/26733/0/
Re: Writting keyword to table [message #180452 is a reply to message #180449] Mon, 03 July 2006 10:55 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Please see whether it helps.
Else
post a sample data, table ddl and the data should be loaded into Table.
Re: Writting keyword to table [message #180459 is a reply to message #180452] Mon, 03 July 2006 11:42 Go to previous messageGo to next message
gconner1997
Messages: 10
Registered: July 2006
Location: New York
Junior Member
Thanks Mahesh,

I have a program that generates the .ctl file, so I am getting the output I want. However, I just figured I could use data from the sqlldr command-line the same way I use a argv in c++ or python, or a $1, $2 in some shell scripts.

Here is an actual example that will work assuming you
replace the userid info with your info:

create table t_myid (
myid varchar2(10),
myfilename varchar2(50)
)

I create a file using VI:
vi myfile.dat:
a
b
c

I create a test control file
test.ctl:
INFILE *
APPEND INTO TABLE T_MYID
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(
MYID NULLIF (MYID=BLANKS),
MYFILENAME "USER"
)

Then I run this:
sqlldr scott/scott@madeup control=test.ctl data=myfile.dat

Then I do a select from my table
select * from t_myid
I get this output:
myid myfilename
a SCOTT
b SCOTT
c SCOTT

Note the line MYFILENAME "USER" in the .ctl file
was replace with 'SCOTT'

Now instead of scott I'd like to load "myfile.dat"
from the command line, since the command line changes
so select * from t_myid: would return:
myid myfilename
a myfile.dat
b myfile.dat
c myfile.dat

instead of :
test.ctl:
INFILE *
APPEND INTO TABLE T_MYID
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(
MYID NULLIF (MYID=BLANKS),
MYFILENAME "USER"
)

I would think this:
test.ctl:
INFILE *
APPEND INTO TABLE T_MYID
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(
MYID NULLIF (MYID=BLANKS),
MYFILENAME "DATA"
)
:would work since sqlloader should replace the keyword DATA with MYFILE.DAT the
same way it would replace "USER" with SCOTT


Therefore in theory if myfile1.dat, myfile2.dat, and myfile3.dat were identical
running:
sqlldr scott/scott@madeup control=test.ctl data=myfile1.dat
sqlldr scott/scott@madeup control=test.ctl data=myfile2.dat
sqlldr scott/scott@madeup control=test.ctl data=myfile3.dat

would return:
myid myfilename
a myfile1.dat
b myfile1.dat
c myfile1.dat
a myfile2.dat
b myfile2.dat
c myfile2.dat
a myfile3.dat
b myfile3.dat
c myfile3.dat

Thanks
--glenn


Re: Writting keyword to table [message #180462 is a reply to message #180459] Mon, 03 July 2006 11:53 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
So?
You are all set ? or What?
Re: Writting keyword to table [message #180464 is a reply to message #180462] Mon, 03 July 2006 11:59 Go to previous message
gconner1997
Messages: 10
Registered: July 2006
Location: New York
Junior Member
Yes, Thanks
Previous Topic: IMPORT Problem NEED HELP quickly
Next Topic: SQL*Loader: remove hexadecimal zero values
Goto Forum:
  


Current Time: Thu Jul 04 19:40:45 CDT 2024