Control file for SQL*Loader
Hello,
I have the following file (2 line) which I want to intend in an oracle database with the SQL*Loader.
tommy050+3423
tom 070-0006
The file consists of two lines and three columns.
Column1 has always 5 digits and is a String. Additional empty digits will be filled with blanks. Here: tommy and tom
Column2 has three digits and is a number. Here: 050 and 070.
Column 3 is also a number and consists of four digits. Additionally there is a fifth digit for the leading sign ("+" or "-"). Here: +3423 and -0006.
This file I want to import in my table MyTab.
MyTab(
thing VARCHAR2(5)
number NUMBER(3)
amount NUMBER
How would the control file for the SQL*Loader look like for this example?
Regards
Homer
This is a start (untested)
LOAD DATA
INFILE 'sample.dat'
BADFILE 'sample.bad'
DISCARDFILE 'sample.dsc'
APPEND
INTO TABLE MyTab
( thing POSITION(1:5) CHAR ,
NUMBER POSITION(6:8) INTEGER,
amount POSITION(9:12) INTEGER )Can you have a column named number?
Similar Messages
-
Concatenate positions in control file for sql*loader utility.
Is there a way to concatenate several character positions in a control file for sql*loader???
example... field1 position(1:3) || position(5:7) ????
I would rather not create any unnecessary temp tables for a straight load...How about...
/code
field1 position(1:7) char "substr(:field1, 1, 3) || substr(:field1, 5)" -
Can I have two Data Files in One control file of sql*loader tool
hi,
Can someone help me out. is it possible to have two Data Files in one control file of Sql*loader.
And isit possible to run 10,000 records before lunch and 10,000 records before tea and 10,000 records before evening session by giving breaks after every 10,000 records.
Thanks
RamYes. You can specify two datafiles in one control file and can load using sql loader.
I give you the sample control file.
Load DATA
INFILE 'TEST1.CSV'
INFILE 'TEST2.CSV'
TRUNCATE
INTO TABLE TEST_P
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(COL_1,
COL_2,
COL_n)
Hope It will help you.
-Karthik -
Substitution for logical OR usage in control file of sql loader
Hi,
can anyone suggest me a substituion method to use the functionality of logical OR in control file developed for sql loader.
Ex:
load data
append
into table ABC
when (1:2) = 'AD'
--AND ((27:28)= '01' OR (27:28)= '02')
AND (1222:1222) = '1'
trailing nullcols
Note: condition commented in the above example need to be replaced.
one way of doing it can be splitting blocks for each condition.
Then it will look like:
load data
append
into table ABC
when (1:2) = 'AD'
AND (27:28)= '01'
AND (1222:1222) = '1'
trailing nullcols
into table ABC
when (1:2) = 'AD'
AND (27:28)= '02'
AND (1222:1222) = '1'
trailing nullcols
So, i'm looking for a better way than this, as i cannot work with the above
splitting logic because i'm dealing with lot many conditions.
Thanx inadvance
KishoreHi,
can anyone suggest me a substituion method to use the functionality of logical OR in control file developed for sql loader.
Ex:
load data
append
into table ABC
when (1:2) = 'AD'
--AND ((27:28)= '01' OR (27:28)= '02')
AND (1222:1222) = '1'
trailing nullcols
Note: condition commented in the above example need to be replaced.
one way of doing it can be splitting blocks for each condition.
Then it will look like:
load data
append
into table ABC
when (1:2) = 'AD'
AND (27:28)= '01'
AND (1222:1222) = '1'
trailing nullcols
into table ABC
when (1:2) = 'AD'
AND (27:28)= '02'
AND (1222:1222) = '1'
trailing nullcols
So, i'm looking for a better way than this, as i cannot work with the above
splitting logic because i'm dealing with lot many conditions.
Thanx inadvance
Kishore -
How do I skip footer records in Data file through control file of sql*loade
hi,
I am using sql*loader to load data from data file and i have written control file for it. How do i skip last '5' records of data file or the footer records to be skiped to read.
For first '5' records to be skiped we can use "skip" to achieve it but how do i acheive for last '5' records.
2)
Can I mention two data files in one control file if so what is the syntax(like we give INFILE Where we mention the path of data file can i mention two data file in same control file)
3)
If i have datafile with variable length (ie 1st record with 200 charcter, 2nd with 150 character and 3rd with 180 character) then how do i load data into table, i mean what will be the syntax for it in control file.
4)if i want to insert sysdate into table through control file how do i do it.
5) If i have variable length records in data file and i have first name then white space between then and then last name, how do i insert this value which includes first name and last name into single column of the table.( i mean how do you handle the white space in between first name and last name in data file)
Thanks in advance
ramYou should read the documentation about SQL*Loader.
-
Control file to sql*loader
Hi,
i'm doing my project work in the data base mangement and i'm not understanding the control file for the sql*loader and how it works...so, anyone please help me by explaining the topic and by sending a sample code...
thanks.Something like
for file in <<my_directory>>
do
sqlldr userid=<<my_connectstring>> data=$file control=<<my_controlfile.ctl>>
donehttp://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch04.htm#1004744 -
How do i map one field to another in control file via SQL Loader
Can someone please reply back to this question
Hi,
I have a flat file (student.dat delimiter %~| ) using control file (student.ctl) through sql loader. Here are the details.
student.dat
student_id, student_firstname, gender, student_lastName, student_newId
101%~|abc%~|F %~|xyz%~|110%~|
Corresponding table
Student (
Student_ID,
Student_FN,
Gender,
Student_LN
Question:
How do i map student_newId field to student_id field in STUDENT DB table so that new id should be inserted in student_id column. How do i specify the mapping in control file. I dont want to create a new column in student table. Please let me know the best way to do this.
Can someone please reply back to this question.
My approach:
In control file i will sepecify the below, Is this a best approach?. Do we have any othe way?
STUDENT_ID *(:STUDENT_NEWID)*,
STUDENT_FN,
GENDER,
STUDENT_LNAME,
STUDENT_NEWID BOUNDFILLER
Thanks
Sunil
Edited by: 993112 on Mar 13, 2013 12:28 AM
Edited by: 993112 on Mar 13, 2013 12:30 AM
Edited by: 993112 on Mar 13, 2013 12:31 AM
Edited by: 993112 on Mar 18, 2013 2:52 AMOK, ok...
Here is the sample data:
101%~|abc%~|F %~|xyz%~|110%~|
102%~|def%~|M %~|pqr%~|120%~|
103%~|ghi%~|M %~|stu%~|130%~|
104%~|jkl%~|F %~|vwx%~|140%~|
105%~|mno%~|F %~|yza%~|150%~|Here is the control file:
LOAD DATA
INFILE student.dat
TRUNCATE INTO TABLE STUDENT
FIELDS TERMINATED BY '%~|' TRAILING NULLCOLS
student_old FILLER
, student_fn
, gender
, student_ln
, student_id
)And here is the execution:
SQL> CREATE TABLE student
2 (
3 student_id NUMBER
4 , student_fn VARCHAR2 (10)
5 , gender VARCHAR2 (2)
6 , student_ln VARCHAR2 (10)
7 );
Table created.
SQL>
SQL> !sqlldr / control=student.ctl
SQL*Loader: Release 11.2.0.3.0 - Production on Tue Mar 19 14:37:31 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 5
SQL> select * from student;
STUDENT_ID STUDENT_FN GENDER STUDENT_LN
110 abc F xyz
120 def M pqr
130 ghi M stu
140 jkl F vwx
150 mno F yza
SQL>:p -
Pass parameter to control file in SQL LOADER
Hi guys,
I need your help.
I'm currently using Linux Enterprise 3.0 and ORACLE database.
I got many ASCII text files in a folder.
And I want to load those text files to database during interval of time.
For example, if in that folders contains 10 text files I'll load one by one until no file in the folder in once time.
What i want is Firstly, i got the name of 10 files then i scan one by one pass its name to control files and start loading.
After that I do with the second file by follow the first step until reach the 10th file.
can anyone help?
TIA
luxSomething like
for file in <<my_directory>>
do
sqlldr userid=<<my_connectstring>> data=$file control=<<my_controlfile.ctl>>
donehttp://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch04.htm#1004744 -
Different log file name in the Control file of SQL Loader
Dear all,
I get every day 3 log files with ftp from a Solaris Server to a Windows 2000 Server machine. In this Windows machine, we have an Oracle Database 9.2. These log files are in the following format: in<date>.log i.e. in20070429.log.
I would like to load this log file's data to an Oracle table every day and I would like to use SQL Loader for this job.
The problem is that the log file name is different every day.
How can I give this variable log file name in the Control file, which is used for the SQL Loader?
file.ctl
LOAD DATA
INFILE 'D:\gbal\in<date>.log'
APPEND INTO TABLE CHAT_SL
FIELDS TERMINATED BY WHITESPACE
TRAILING NULLCOLS
(SL1 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
SL2 char,
SL3 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
SL4 char,
SL5 char,
SL6 char,
SL7 char,
SL8 char,
SL9 char,
SL10 char,
SL11 char,
SL12 char,
SL13 char,
SL14 char,
SL15 char)
Do you have any better idea about this issue?
I thought of renaming the log file to an instant name, such as in.log, but how can I distinguish the desired log file, from the other two?
Thank you very much in advance.
Giorgos BaliotisI don't have a direct solution for your problem.
However if you invoke the SQL loader from an Oracle stored procedure, it is possible to dynamically set control\log file.
# Grant previleges to the user to execute command prompt statements
BEGIN
dbms_java.grant_permission('bc4186ol','java.io.FilePermission','C:\windows\system32\cmd.exe','execute');
END;
* Procedure to execute Operating system commands using PL\SQL(Oracle script making use of Java packages
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
finalCommand = new String[4];
finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
final Process pr = Runtime.getRuntime().exec(finalCommand);
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
}).start();
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("Process err :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
}).start();
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
* Oracle wrapper to call the above procedure
CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
* Now invoke the procedure with an operating system command(Execyte SQL-loader)
* The execution of script would ensure the Prod mapping data file is loaded to PROD_5005_710_MAP table
* Change the control\log\discard\bad files as apropriate
BEGIN
Host_Command (p_command => 'sqlldr system/tiburon@orcl control=C:\anupama\emp_join'||1||'.ctl log=C:\anupama\ond_lists.log');
END;Does that help you?
Regards,
Bhagat -
Controller file for SQL Loader
Guys,
My data is coming in flat from some third party in the below format
1,Stewart,"Current Address: Street-A, Flat-507, London, UK
Permanent Address: Street-B, Flat-201, London, UK"
2,Patrick,"Current Address: Street-A, Flat-507, Bangalore, India
Permanent Address: Street-B, Flat-201, Delhi, India"
I want to load the data in a custom table by using a SQL loader program which will use a controller program. This program needs to populate the table in below manner
SEQ EMPLOYEE ADDRESS INFORMATION
1 Stewart Current Address: Street-A, Flat-507, London, UK
Permanent Address: Street-B, Flat-201, London, UK
2 Patrick Current Address: Street-A, Flat-507, Bangalore, India
Permanent Address: Street-B, Flat-201, Delhi, India
Could you guys please help me in writing the controller file to read the data from file and populate the table as described above. Thanks.
-SunilIt is a little hard to tell exactly what your data file looks like and what you want your results to be, due to this forum mangling things a bit and adding extra lines and such. In general you can either use CONTINUEIF or CONCATENATE. I have demonstrated both below. When using CONTINUEIF, it assumes each additional line begins with the word "Permanent". When using CONCATENATE, it assumes each two lines constitutes one record. I have also used REPLACE to add a line feed in front of "Permanent", after it is removed during continuation or concatenation.
SCOTT@orcl12c> host type test.dat
1,Stewart,"Current Address: Street-A, Flat-507, London, UK
Permanent Address: Street-B, Flat-201, London, UK"
2,Patrick,"Current Address: Street-A, Flat-507, Bangalore, India
Permanent Address: Street-B, Flat-201, Delhi, India"
SCOTT@orcl12c> host type test.ctl
load data
infile test.dat
continueif next preserve (1:9) = 'Permanent'
into table test_tab
fields terminated by ','
optionally enclosed by '"'
trailing nullcols
(seq, employee,
address_information "replace (:address_information, 'Permanent', CHR(10) || 'Permanent')")
SCOTT@orcl12c> host type test2.ctl
load data
infile test.dat
concatenate 2
into table test_tab
fields terminated by ','
optionally enclosed by '"'
trailing nullcols
(seq, employee,
address_information "replace (:address_information, 'Permanent', CHR(10) || 'Permanent')")
SCOTT@orcl12c> create table test_tab
2 (seq number,
3 employee varchar2(8),
4 address_information varchar2(200))
5 /
Table created.
SCOTT@orcl12c> host sqlldr scott/tiger control=test.ctl log=test.log
SQL*Loader: Release 12.1.0.1.0 - Production on Mon Dec 16 13:11:40 2013
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 1
Commit point reached - logical record count 2
Table TEST_TAB:
2 Rows successfully loaded.
Check the log file:
test.log
for more information about the load.
SCOTT@orcl12c> column address_information format a60
SCOTT@orcl12c> select * from test_tab
2 /
SEQ EMPLOYEE ADDRESS_INFORMATION
1 Stewart Current Address: Street-A, Flat-507, London, UK
Permanent Address: Street-B, Flat-201, London, UK
2 Patrick Current Address: Street-A, Flat-507, Bangalore, India
Permanent Address: Street-B, Flat-201, Delhi, India
2 rows selected.
SCOTT@orcl12c> truncate table test_tab
2 /
Table truncated.
SCOTT@orcl12c> host sqlldr scott/tiger control=test2.ctl log=test2.log
SQL*Loader: Release 12.1.0.1.0 - Production on Mon Dec 16 13:11:40 2013
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 2
Table TEST_TAB:
2 Rows successfully loaded.
Check the log file:
test2.log
for more information about the load.
SCOTT@orcl12c> select * from test_tab
2 /
SEQ EMPLOYEE ADDRESS_INFORMATION
1 Stewart Current Address: Street-A, Flat-507, London, UK
Permanent Address: Street-B, Flat-201, London, UK
2 Patrick Current Address: Street-A, Flat-507, Bangalore, India
Permanent Address: Street-B, Flat-201, Delhi, India
2 rows selected. -
Role of "str ' EORD \r\n'" value in control file in sql loader
Hi All,
Could any one please let me know what is the exact use of "str '<EORD>\r\n'" statement in control file ?, while populating data from .dat file into database table.
When I am trying with this option, I am able to load a single record into a database table. If I remove this statement form control file, complete records from file get populated into table. I am using Linux server for imp data with sqlloader.
Also, Does there any difference to use this statement in control file on Linux server and on AIX server ?
Here is the structure of my ctl file.
load data
infile 'data/EZMAIL/CDSWEB.EZMAIL.dat'
*"str '<EORD>\r\n'"*
into table CDSWEB.EZMAIL
fields terminated by '#<EOFD>#'
trailing nullcols (
Thanks
PravinHi Harry,
Thanks for suggestion, I tried with "str '\n'" instead of "str '<EORD>\r\n'" in control file and it worked properly.
But I am still confuse, Does it really a Linux issue ? as this doesn't work on Linux and the same work on AIX.
This is a sample record form .dat file which I am trying to load into database table.
100#<EOFD>#12#<EOFD>#0#<EOFD>##<EOFD>#2nd Year Term Letter#<EOFD>#80#<EOFD>#2000-01-05-05.00.00.000000#<EOFD>#1#<EOFD>#80#<EOFD>#IMAGE.dat.002.lob#<EOFD>#100#<EOFD>#1#<EOFD>#2nd Year Term Renewal Letter.JPG#<EOFD>#0#<EOFD>#image/pjpeg#<EOFD>##<EOFD>#1#<EOFD>#0#<EOFD>##<EOFD>#100#<EOFD>#100#<EOFD>##<EOFD>#<EORD>
Thanks,
Pravin -
Utility to convert ASE fmt files to ctl files for sql*loader
Does anyone have a utility to convert bcp format files to oracle ctl files for use with sql*loader?
Hi,
The Oracle Migration Workbench will produce both BCP and the equivalent Oracle .ctl files for all tables in a database.
Regards
John -
New Line in data file for sql loader
Hi all,
I have a requirement to load a data file in which some of the rows are in new line as given in following example. If i put a '\n' character in control file, then it will load only those records which have newline in them ignoring non new line ones. please have a look at control fileand provide a solution to it :-
32 grand street ~NY~NY
42 riverdrive,
apt 1B ~PL~TX
Richardson road
apt 32~ SF ~CA
As you see there are newline characters in record 2 and 3, right now my control file looks like this -
LOAD DATA
INFILE 'example.txt' "STR '\r\n'"
INTO TABLE "temp_table"
INSERT
FIELDS TERMINATED BY '~'
TRAILING NULLCOLS
(ADDRESS1,
CITY,
STATE)
If i remove "STR '\r\n'" , then the data gets loaded into different rows like the third record looks like this -
ADDRESS CITY STATE
Richardson road null null
apt 32 SF CA
Please help.Your requirement is very unclear.
Is this your INPUT ?
--record 1
32 grand street ~NY~NY
--record 2
42 riverdrive, --"NL"
apt 1B ~PL~TX
--record 3
Richardson road --"NL"
apt 32~ SF ~CAIs this your OUTPUT?
ADDRESS CITY STATE
32 grand street NY NY
42 riverdrive, null null
apt 1B PL TX
Richardson road null null
apt 32 SF CAAre you using Linux or Windows platform?
You should have only one record terminator character.
*\r\n* is Windows The End of Line character (The Carriage Return + The Line Feed).
"STR '\r\n'" = "str X'0D0A'"
If there is no data after \r\n, columns will be null.
http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_concepts.htm#i1005800 -
How to pass value to a control file in sql loader
Hello
please want to know if i can pass a value to a control file?
I have a table which i will populate using a control file but there is a field in the table which i will pass the date of the file.
how can i archive this
Thanks
Edited by: kama021 on Apr 18, 2012 3:49 AMThe content of the control file must be made dynamically to include desired value.
Handle: kama021
Status Level: Newbie
Registered: Jun 9, 2009
Total Posts: 154
Total Questions: 42 (25 unresolved)
Why so many unanswered questions?
Edited by: sb92075 on Apr 18, 2012 6:34 AM -
Not loading from flat file using SQL*Loader
Hi,
I am trying to load from an excel file.
first i converted excel file into csv file and save it as as dat file.
in the excel file one column is salary and the data is like $100,000
while converting xls to csv the salary is changed to "$100,000 " (with quotes and a space after the amount)
after the last digit it will put a space.
in the control file of sql*loader i had given
salary "to_number('L999,999')"
my problem is the space after the salary in the dat file.---> "$100,000 "
what changes i have to make in the to_number function which is in the control file.
Please guide me.
Thanks & Regards
Salih KM
Message was edited by:
kmsalihThanks a lot Jens Petersen
It's is loading ..........
MI means miniute.
am i correct.
but i didn't get the logic behind that.
can u please explain that.
Thanks & Regards
Salih KM
Maybe you are looking for
-
I recently changed my email address and need to change my icloud account on both my itunes and iphone. How do I do this without completely wiping the phone. Also I tried to update to iOS6 and it is asking for my password under my old signin and locke
-
BPEL End Point URL using External Load Balancer URL
Hi All, We have Oracle SOA Suite installed in a clustered environment as per the Enterprise Deployment Guide 10g Release 310.1.3.3.0 E10294-02. I have deployed a BPEL process to the clustered environment and the end point refers to the internal url o
-
Need Suggestion about Solman support & testing E CATT feature
Hi Solman Experts . I need your Strong suggestion. Actually i am working in ABAP module , I recently joined as a fresher in small company, I got opportunity to go Saudi for "Solman support & testing ,E CATT" in big MNC . Now i need suggestion ,
-
How can i obtain ID-tag (... and an unique ID?) from m4a, m4p, mp3 file bought on iTunes Music Store? I need to build C/C++ application to make this. Best regards.
-
Authorizing more than 5 computers - How to switch or edit authorization???
Hello, Is it possible to switch authorizations for computers for iTunes? I'm trying to get music from one computer to another, but it tells me I already have 5 computers authorized...I'm not sure how that happened, as I have only authorized 3 compute