Home » SQL & PL/SQL » SQL & PL/SQL » sqlloader control file
sqlloader control file [message #35303] Fri, 04 February 2005 07:58 Go to next message
Ant
Messages: 13
Registered: February 2000
Junior Member
The external files have the name convention: TTX[[1-10]].txt , total of 10 files to be loaded.
I built a control file:

load data
infile *
BADFILE 't.bad'
APPEND
into table Trans
fields terminated by ',' optionally enclosed by '"'
(
col1,
F1,
F2,
F3 filler,
F4,
F5,
F6
F7 filler
)

How do I insert col1 value with the file name convention
eg: if TTX3.txt file has 100 records to be loaded into db, all these 100 data records would have col1 value with TTX3.
Please help.
Re: sqlloader control file [message #35316 is a reply to message #35303] Sat, 05 February 2005 00:22 Go to previous messageGo to next message
Sreedhar Reddy
Messages: 55
Registered: January 2002
Member
try using this
load data
infile 'c:datamydata.csv'
into table emp
fields terminated by "," optionally enclosed by '"'
( empno, empname, sal, deptno )
Re: sqlloader control file [message #35320 is a reply to message #35316] Sat, 05 February 2005 08:00 Go to previous messageGo to next message
Ant
Messages: 13
Registered: February 2000
Junior Member
Thanks. still...my question is
The col1 value is not included in the file content but actually represent the filename.
Re: sqlloader control file [message #35341 is a reply to message #35320] Mon, 07 February 2005 06:24 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
use a little scripting.
use whatever you like
sed/perl/bash/korn/sqlplus/... whatever that works for you.
--
-- let this be sample table.
--
bash-2.03$ desc mutation mag.sample

Table:mag.sample
 Name                                Null?    Type
 ----------------------------------- -------- ------------------------
 FILENAME                                     VARCHAR2(10)
 NAME                                         VARCHAR2(10)
 ADDRESS                                      VARCHAR2(10)

--
-- these are our data files
--
bash-2.03$ cat file1.dat
Dave,2 main st
Bob,3 cross st

bash-2.03$ cat file2.dat
otherDave,2 main st
otherBob,3 cross st

--
-- lets load those files.
-- here 'sample' is the script that takes one parameter ( name of the file)
-- loading file1.dat

bash-2.03$ sample file1.dat

SQL*Loader: Release 9.2.0.4.0 - Production on Mon Feb 7 10:11:44 2005

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Commit point reached - logical record count 2

--
-- loading file2.dat
--

bash-2.03$ sample file2.dat

SQL*Loader: Release 9.2.0.4.0 - Production on Mon Feb 7 10:11:50 2005

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Commit point reached - logical record count 2

--
-- checking the data
--
bash-2.03$ query mutation mag.sample

FILENAME   NAME       ADDRESS
---------- ---------- ----------
file1.dat  Dave       2 main st
file1.dat  Bob        3 cross st
file2.dat  otherDave  2 main st
file2.dat  otherBob   3 cross st

--
-- this is the script
-- have a standard control file template.ctl
-- for every load, Edit the template and  create a new control file.
-- use that new controlfile to load.
-- make use of constant cluase in sql*loader.
--
bash-2.03$ cat sample
#!/usr/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/9.2.0
export PATH=$PATH:$ORACLE_HOME/bin
sed s/FILENAME/$1/ template.ctl > /tmp/sample.ctl
sqlldr userid=mag/mag control=/tmp/sample.ctl
bash-2.03$ cat template.ctl
LOAD DATA
infile 'FILENAME'
append
INTO TABLE sample
FIELDS TERMINATED BY ","
trailing nullcols
(
filename constant 'FILENAME',
name,
address
)
--
-- this is one such created temporary control file ( for every load)
--
bash-2.03$ cat sample.ctl
cat: cannot open sample.ctl
bash-2.03$ cat /tmp/sample.ctl
LOAD DATA
infile 'file2.dat'
append
INTO TABLE sample
FIELDS TERMINATED BY ","
trailing nullcols
(
filename constant 'file2.dat',
name,
address
)
Re: sqlloader control file [message #35354 is a reply to message #35341] Mon, 07 February 2005 20:00 Go to previous message
Ant
Messages: 13
Registered: February 2000
Junior Member
Mahesh,
Thanks you so much!
Previous Topic: SET DOCUMENT OFF|ON
Next Topic: Calling an Oracle Procedure repetitively
Goto Forum:
  


Current Time: Thu Dec 26 07:56:06 CST 2024