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
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)" -
Load multiple records in 1 table from 1 line in text file w/sql loader
hi guys,
quick question, perhaps someone can help. searched around and didn't see this question asked before, and can't find any answer in SQL Loader faqs or docs.
i know i can extract multiple logical records from a single physical record in the input file as two logical records, and then use two into tables clauses to load the data into the table. see oracle 9i sql loader control file reference chapter 5 to see what i am talking about.
but my question follows:
cust_id amount1_val amount1_qual amount2_val amount2_qual amount3_val amount3_qual
123 1500.35 TA 230.34 VZ 3045.50 TW
basically i want to use one sql loader statement to load these 3 records into 1 table. the issue for me is that i need to re-use the cust_id for all 3 records as the key, along with the qualifier code. the example in the Oracle docs only works for data where the logical records are completely separate -- no shared column values.
i'm sure this is possible, perhaps using some :cust_id type parameter for the 2nd and 3rd records, or something, but i just don't have enough knowledge/experience with sql loader to know what to do. appreciate any help.
wayneHi wayne,
I found an example on what exactly you were looking for from an SQL*Loader documentation. Please see if it of some help to you
EXAMPLE
The control file is ULCASE5.CTL.
1234 BAKER 10 9999 101
1234 JOKER 10 9999 777
2664 YOUNG 20 2893 425
5321 OTOOLE 10 9999 321
2134 FARMER 20 4555 236
2414 LITTLE 20 5634 236
6542 LEE 10 4532 102
2849 EDDS xx 4555
4532 PERKINS 10 9999 40
1244 HUNT 11 3452 665
123 DOOLITTLE 12 9940
1453 MACDONALD 25 5532
In the above datafile
Column1 - Empno
Column2 - ENAME
Column3 - Depno.
Column4 - MGR
Column5 - Proj no.
-- Loads EMP records from first 23 characters
-- Creates and loads PROJ records for each PROJNO listed
-- for each employee
LOAD DATA
INFILE 'ulcase5.dat'
BADFILE 'ulcase5.bad'
DISCARDFILE 'ulcase5.dsc'
1) REPLACE
2) INTO TABLE emp
(empno POSITION(1:4) INTEGER EXTERNAL,
ename POSITION(6:15) CHAR,
deptno POSITION(17:18) CHAR,
mgr POSITION(20:23) INTEGER EXTERNAL)
2) INTO TABLE proj
(empno POSITION(1:4) INTEGER EXTERNAL,
3) projno POSITION(25:27) INTEGER EXTERNAL) -- 1st proj
Notes:
REPLACE specifies that if there is data in the tables to be loaded (EMP and PROJ), SQL*loader should delete the data before loading new rows.
Multiple INTO clauses load two tables, EMP and PROJ. The same set of records is processed three times, using different combinations of columns each time to load table PROJ.
Regards,
Murali Mohan -
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
HomerThis 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? -
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. -
How to get Dynamic data file in SQL*Loader?
Hi all,
I have a requirement that needs to import data everyday using background process. I have created a control file with the fixed datafile name and calling it through java. It is working fine.
The thing is data file name is not constant, it changes everyday (I mean the file name format is YearMonthDate_Clients.cvs). But the the data file location is fixed location.
How can I get the data file name dynamically?
Can someone has the answer?
Thanks in advance,
KalyogiI'm not a JAVA developer, but I've used this before
File folder = new File("c:/");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles.isFile()) {
--Here the filename is printed, but I'm sure you can pass this to whatever/however you are invoking SqlLdr
System.out.println("File " + listOfFiles[i].getName()); -
Export data ready for sql loader
Hi,
I need to export some data from my database ready to be used by sql loader ... what are tools can I use? Using sqlplus (i.e. spool file.csv select c1||";"||c2||";" from table; spool off) is the only tool I can use?Hello,
You have multiple choices depending upon your oracle version on both source and target.
*1. Conventional export/import (no need to generate csv)*
*2. Datapump (10g)*
*3. Extracting .csv file using sql and loading using sqlldr*
*4. External table unloading data using datapump.*
*5. External table using .csv file generated via sql script.*
Regards -
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 -
Format input for Sql*Loader
I have a problem in formating an input file for Sql*Loader
The file has the following format:
1 Jeff
2 Kyle
3 Tom
1 Lisa
2 Bryan
3 Max
4 Rob
5 Steve
1 Richard
2 Mary
and so on
the file should look as follows to process with Sql*Loader:
1 Jeff 2 Kyle 3 Tom
1 Lisa 2 Bryan 3 Max 4 Rob 5 Steve
1 Richard 2 Mary
any suggestions?
Edited by: royce on Sep 18, 2008 2:08 AMroyce wrote:
I have a problem in formating an input file for Sql*Loader
The file has the following format:
1 Jeff
2 Kyle
3 Tom
1 Lisa
2 Bryan
3 Max
4 Rob
5 Steve
1 Richard
2 Mary
and so on
the file should look as follows to process with Sql*Loader:
1 Jeff 2 Kyle 3 Tom
1 Lisa 2 Bryan 3 Max 4 Rob 5 Steve
1 Richard 2 Mary
any suggestions?
Edited by: royce on Sep 18, 2008 2:08 AMActually, looking at your data again, you don't have a consistent format, so this makes it really difficult for something like SQL*Loader to process. If there were just e.g. 3 rows per record then that would be simple, but you are expecting SQL*Loader to look ahead to determine if there is more data or if it's reached the end of the record.
You would be better to load the data (external tables would probably make it quicker and easier as the data will come in the order as it is specified in the file, which would help as you have no group identifier against the sets of records) as it is and then use SQL to process them.
You haven't specified the resulting table that the data is loaded into. Is that just one single VARCHAR column with all the data concatenated or is it several columns (one for each name)? -
SQL*Loader to insert data file name during load
I'd like to use a single control file to load data from different files (at different times) to the same table. I'd like this table to have a column to hold the name of the file the data came from. Is there a way for SQL*Loader to automatically do this? (I.e., as opposed to running an update query separately.) I can edit the control file before each load to set a CONSTANT to hold the new data file name, but I'd like it to pick this up automatically.
Thanks for any help.
-- HarveyHello Harvey.
I've previously attempted to store a value into a global/local OS variable and use this within a SQL*Loader control file (Unix OS and Oracle versions between 7.3.4 and 10g). I was unsuccessful in each attempt and approach I could imagine. It was very easy to use a sed script to make a copy of the control file, changing a string within it to do this however.
Do you really want to store a file name on each and every record? Perhaps an alternative would be to use a relational model. Create a file upload log table that would store the file name and an upload # and then have the SQL*Loader control file call a function that would read that table for the most recent upload #. You'll save some disk space too.
Hope this helps,
Luke -
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 -
Changing the File path for SQL Loader Recognition
I am learning how to create a control file. The names.ctl file was placed in "Names" folder in my "C:\Windows" file.
I get the following error when trying to run the script for sqlldr:
Sql*Loader-500 Unable to open file.
Sql*Loader-553 file not found
Sql*Loader-System error: the system cannot find the specified file.
The path on the folder in c:\Windows\names\names.ctl
How do I make SQL Loader recognize it?Pl post details of OS and database versions. Have you tried this ?
sqlldr CONTROL=c:\Windows\names\names.ctl ...HTH
Srini -
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 -
How to set default directory for SQL LOADER
hi all,
i wanted to know how can we setup a default directory for SQL LOADER if at all we can. i connot place my control and data files in local system and use them at command prompt. rather i wanted to know if we can set default directory that the loader can use. this requirement is basically to enable all the clients to upload the data placed on the server and use the loader utility.
thanks in advance,
BasavrajElla,
You don't say which version of SQL Developer you are using via Citrix, but just setting the SQLDEVELOPER_USER_DIR hasn't worked for a long time (see Re: SQLDEVELOPER_USER_DIR does not function anymore). Also, since version 1.5, the default for the user directory (now set via ide.user.dir as shown below) is under the user profile area (relative to %APPDATA%), which you should be able to write to, even on Citrix.
Assuming that neither of those help, you will need to get whoever installed SQL Developer on the Citrix C: drive to modify the sqldeveloper.conf to have a line like, where the path exists for everyone who will be using the shared SQL Developer (assumes everyone has a H: drive):
AddVMOption -Dide.user.dir=H:\sqldeveloperAn alternative (depending on how you start SQL Developer via Citrix), is to create your own shortcut to start SQL Developer with something like:
sqldeveloper -J-Dide.user.dir="%SQLDEVELOPER_USER_DIR%"theFurryOne -
Problem loading XML-file using SQL*Loader
Hello,
I'm using 9.2 and tryin to load a XML-file using SQL*Loader.
Loader control-file:
LOAD DATA
INFILE *
INTO TABLE BATCH_TABLE TRUNCATE
FIELDS TERMINATED BY ','
FILENAME char(255),
XML_DATA LOBFILE (FILENAME) TERMINATED BY EOF
BEGINDATA
data.xml
The BATCH_TABLE is created as:
CREATE TABLE BATCH_TABLE (
FILENAME VARCHAR2 (50),
XML_DATA SYS.XMLTYPE ) ;
And the data.xml contains the following lines:
<?xml version="2.0" encoding="UTF-8"?>
<!DOCTYPE databatch SYSTEM "databatch.dtd">
<batch>
<record>
<data>
<type>10</type>
</data>
</record>
<record>
<data>
<type>20</type>
</data>
</record>
</batch>
However, the sqlldr gives me an error:
Record 1: Rejected - Error on table BATCH_TABLE, column XML_DATA.
ORA-21700: object does not exist or is marked for delete
ORA-06512: at "SYS.XMLTYPE", line 0
ORA-06512: at line 1
If I remove the first two lines
"<?xml version="2.0" encoding="UTF-8"?>"
and
"<!DOCTYPE databatch SYSTEM "databatch.dtd">"
from data.xml everything works, and the contentents of data.xml are loaded into the table.
Any idea what I'm missing here? Likely the problem is with special characters.
Thanks in advance,I'm able to load your file just by removing the second line <!DOCTYPE databatch SYSTEM "databatch.dtd">. I dont have your dtd file, so skipped that line. Can you check if it's problem with ur DTD?
Maybe you are looking for
-
Problem in assigning field symbol to a nested internal table
Hi All, I have searched the forum but could not find a solution to this problem. I have a requirement where I need to define an internal table within an internal table, so I have used pointer within the outer internal table(itab2) which point to the
-
Macbook Air - using Cinema Display usb and firewire?
Hello, This is the first post for me, however the answer will determine whether I make the jump for an air. Will the usb hub on the cinema displays work with the macbook air dvi output connector. (essential for me to purchase) would firewire work (bo
-
Is there any way to save all of my imessages with a person on to my computer for free?
I've looked at multiple programs but they all cost money. Is there a way to save an entire imessage conversation with a person on to my PC for free? I backed up my phone on itunes and when I looked at the backup I could not find my texts in any of th
-
Hi All, Can anyone help me out with the documents related to Contract Management in SRM like config guides and other doc's. please send them to my id <removed by moderator> Thanks, James
-
InDesign CC 2014 + Mavericks Issues?
I'm running a 3-month old Mac Air with all the upgrades, bells & whistles. I thought I'd demo InDesign and CreativeCloud today and see how they worked for me on this machine. They both downloaded completely, but InDesign crashes upon opening. Are