- 04-11-2010 #1
Member
- Join Date
- 01 Apr 2010
- Posts
- 31
- Points
- 910
control file help
Hi Im importing a simple data set using sql loader, below is the controll file im using...
The field named 'CustName' imports all the records but surround them in the oracle table with single quotes ... eg 'Dave' .. not Dave.. how can i alter the control file to remove these sinngle quotes when the data is imported...
Also....
The field named 'registered' contains data as 'true' or 'false' in the csv... i need to import this into oracle as 1 for true and 0 for false... how can i alter the control file to do this?
my control file is as follows:
OPTIONS (ERRORS=999)
LOAD DATA
INFILE "c:\test.csv"
BADFILE "c:\test.bad"
INSERT
INTO TABLE test
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(CustName,
Registered)
-
- 04-12-2010 #2
- 04-12-2010 #3
Member
- Join Date
- 01 Apr 2010
- Posts
- 31
- Points
- 910
Re: control file help
I have managed to use decode to turn false/true into y/n and also a substr function to remove enclosing single speach marks...
the next problem I am facing is commas in the address field..
do you have any suggestions how to deal with the commas or alternative soloutions to the others?
2 rows of data are as follows... it is representative of the entire data set.. (comma in second line of address 1)
1,'Mr','John L','Davis','1234','19 belsover Street','dales court','pembrokshire','uk',01/04/2000,1.345,True,
2,'Mrs','Christine','Dunn','3241','24,arly Street','spanish gardens','pembrokshire','uk',01/04/2000,3.454,True,
The above lines are being sent into a different table:
CustiD - Number(1)
Suffix - VarChar2 (3)
Fname -VarChar2 (20)
Lname -VarChar2 (20)
CustSpecNo - Number(4)
Address1 -VarChar2 (100)
Address2 -VarChar2 (100)
Address3 -VarChar2 (100)
Address4 -VarChar2 (100)
Datejoined - Date
...
I want to use sql loader to get them into this table... having problems with data and the commas now.... '24,arly Street'
Any ideas?
- 04-12-2010 #4
Re: control file help
You shoudln't need substr() to replace the single quotes as your strings should be delimited by double quotes as you instructed SQL*Loader in your control file; convert the ' to " and your single quote problem disappears. So will your embedded comma issue as they will be part of known string data. This:
'Mr','John L','Davis','1234','19 belsover Street','dales court','pembrokshire','uk',01/04/2000,1.345,True,
'Mrs','Christine','Dunn','3241','24,arly Street','spanish gardens','pembrokshire','uk',01/04/2000,3.454,True,
should be written like this:
"Mr","John L","Davis","1234","19 belsover Street","dales court","pembrokshire","uk",01/04/2000,1.345,True,
"Mrs","Christine","Dunn","3241","24,arly Street","spanish gardens","pembrokshire","uk",01/04/2000,3.454,True,
Fix your data file to fix your 'problems'.
- 04-13-2010 #5
Re: control file help
No need to change the Data file (.csv)
You just have to change the control file slightly.
Code sql:OPTIONS (ERRORS=999) LOAD DATA INFILE "c:\test.csv" BADFILE "c:\test.bad" INSERT INTO TABLE test FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY "'" TRAILING NULLCOLS

Raj.
- 04-13-2010 #6
Member
- Join Date
- 01 Apr 2010
- Posts
- 31
- Points
- 910
Re: control file help
I fixed it by using OPTIONALLY ENCLOSED BY "'" instead of '"' but if we take the following examples...
'24,arly street'
'18 matthew's close'
... one string including an embedded single quote and one an embeddedcomma
if i dont use OPTIONALLY ENCLOSED BY "'" ... and i do use a substring function then "24, arly street" is not imported because of the embedded comma but "18 matthew's close" is imported correctly and includes the embedded single quote.
if i do use OPTIONALLY ENCLOSED BY "'" then "24, arly stret" is imported correctly, however this time the row that contained "18 matthew's close" is moved to the bad file because that embedded single speach mark breaks the file.
so i think the only way i can make sure that commas and embedded single quotes are imported into the column is by (and correct me if im wrong).. if i do use OPTIONALLY ENCLOSED BY "'" ... and then on that column in the control file put something in to escape that embedded single quote?
any idea how I would do this? escaping embedded single quotes that is?
- 04-13-2010 #7
- 04-14-2010 #8
Member
- Join Date
- 01 Apr 2010
- Posts
- 31
- Points
- 910
Re: control file help
but say this was not an option, how can i use a string function etc to escape the ingle quotes inbetween the enclosing single quotes?
im just trying to learn and play around, any help you could give me would greatly be appriciated
- 04-14-2010 #9
Member
- Join Date
- 01 Apr 2010
- Posts
- 31
- Points
- 910
Re: control file help
The problem is that I have been given a csv file with about 20 columns, .. all the strings are enclosed in single quotes.. so theres not alot I can do to convert these into double quotes...
either way lets say i didnt convert the single quotes, is there not a function that will escape sinlge quotes in the string?
- 04-14-2010 #10
Re: control file help
You cannot. To preserve the apostrophes you need to change the string enclosure character to " because sql*loader takes every occurrence of the delimmiter pairs to define a string and your apostrophe terminates the string it is part of when you tell the utility to use ' to enclose strings. You have already discovered this behaviour. You could, of course, change all of your apostrophes to " then go through the data in the table and convert them back with translate() but you'd still be changing characters in your data file and it appears that changing characters in your data file is not an option simply because you don't want it to be. Yes, there are other options such as writing an OCI/OCCI program to load the data in whatever format you decide you want, writing a Pro*C program to do the load, create an external table and use insert statements to load your data from the external table to your 'permanent' table but using an external table would cause you to run into this same problem as external tables are processed by sql*loader.
Other Solutions
-
Grid Control & 9i database
By rsampson in forum Oracle DatabaseReplies: 3Last Post: 03-03-2011, 03:16 PM -
Database Control in cluster environment
By Floridadba in forum Oracle DatabaseReplies: 7Last Post: 10-22-2010, 09:13 PM -
How control the access to a FORM
By softd3v in forum Oracle Forms and ReportsReplies: 1Last Post: 08-14-2010, 06:09 PM -
Problem with sql loader control file date format
By anijan in forum Other Development ToolsReplies: 9Last Post: 03-10-2010, 07:11 AM






