Question

SQL*Loader How To strip out CR/LF in one column

Asked by: rowek

We have a very simple need and have received a lot of conflictig advise.  The simple question is "How do I remove a CR or LF out of one column contained in a CSV text INFILE?"   I want to do this inside the SQL*Loader 10g CTL file below.  The rest of this proces has run for four months as is, but we now want to remove these characters from the COMMENTS column to include its data as well.  

Note that MS Access is the source database, we run a TransferText to produce the CSV text file.  CR/LF is legal in MS Access but not in Oracle, so we need to get SQL*Loader to strip these out.  Must be done here, not upstream.  Thanks!

LOAD DATA
INFILE      'Refer to app.config file'
BADFILE     'Refer to app.config file'
DISCARDFILE 'Refer to app.config file'
APPEND
INTO TABLE dairy.insp
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
  insp_ID INTEGER EXTERNAL,
  Insp_Empl_ID CHAR,
.
. <some detail removed>
.
  SA_Date_Hazard_Analysis_Issue  "to_date(:SA_Date_Hazard_Analysis_Issue,'MM/DD/YYYY HH24:MI:SS')",
  SA_Date_HACCP_Plan_Issue        "to_date(:SA_Date_HACCP_Plan_Issue,'MM/DD/YYYY HH24:MI:SS')",
  SA_Date_Prereq_Programs_issue  "to_date(:SA_Date_Prereq_Programs_issue,'MM/DD/YYYY HH24:MI:SS')",
  Insp_Order  INTEGER EXTERNAL,
  COMMENTS CHAR,   <=========== Need to remove CR/LRs from this column
  CREATE_DATE "to_date(:CREATE_DATE,'MM/DD/YYYY HH24:MI:SS')",
  CREATE_USER CHAR,
  MODIFY_DATE "to_date(:MODIFY_DATE,'MM/DD/YYYY HH24:MI:SS')",
  MODIFY_USER CHAR,
  PROGRAM_USE CHAR,
  Upload_Date     "to_date(:Upload_Date ,'MM/DD/YYYY HH24:MI:SS')",
  Press_Insp  CHAR
)

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-08-07 at 08:31:40ID23629737
Tags

Oracle

,

SQL*Loader

,

10g

,

Strip out linefee

Topics

Oracle 10.x

,

Oracle 11.x Database

,

Oracle Database

Participating Experts
3
Points
500
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SQL LOADER:carraige return inside field value
    I am trying to load data into Oracle using SQL Loader. One field is of datatype varchar(255) and has carraige returns inside it. When I try to load the data it takes the carraige return , line feed as an end of line and tries to continue after that and the operation fails. Is...
  2. Loading file data to Oracle (Sql*Loader)
    Hello experts.Hoping to get answer for this sql*loader question. I have a flat file employee dat(emp.txt) as follows. THU JUN 01 00:00:05 2000 FName = Robert1 LName = Seni1 UserID = Usr20 FRI JUN 02 00:11:52 2000 FName = Robert2 LName = Seni2 UserID = Usr21 SAT JUN 0...
  3. SQL*LOADER
    I am trying to load a flat file into Oracle using SQL*LOADER. The problems is with a date field. The data for the date field looks like the following. 990221 13:46:07 every time I try to load it compains about the format, is there away to format the data in the SQL*LOADER s...
  4. SQL Loader problems with <CR> in LONG fields
    I am using SQL Loader 8.1.7.0.0 to load a text file containing four fields, one of those four being of the LONG datatype. This LONG field is for comments and often contains Carriage Returns. I've read everything I can in here and at ORACLE to try to KEEP those carriage return...
  5. Sql loader
    Index Search Add FAQ Ask Question Oracle SQL*Loader FAQ $Date: 09-Jul-2005 $ $Revision: 1.30 $ $Author: Frank Naudé $ Topics What is SQL*Loader and what is it used for? How does one use the SQL*Loader utility? Is there a SQL*Unloader to download data to a flat ...
  6. Loading Data using SQL Loader with CR/LF in the data an…
    Hi, I am trying to use use SQL Loader on Windows to load data in Oracle. I have created data file using SQLPlus with pipe delimited data. I have some fields which contain CR/LF charcters in the data. So I tried to use Stream format for infile. And tried to put recrod termi...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: gatorvipPosted on 2008-08-07 at 09:02:23ID: 22182320

If your records are *not* delimited by CR/LF then you can do a simple replace

 REPLACE(COMMENTS ,chr(13)||chr(10),' ') COMMENTS

 

by: rowekPosted on 2008-08-07 at 09:09:57ID: 22182414

Actually I think I will need an OR.
My fault, but it can be either a CR or a LF or both.   I will look at text file with a hex editor and post more detail, but if you could help me with and OR situaiton I should be able to award points.  Thanks!

 

by: gatorvipPosted on 2008-08-07 at 09:17:35ID: 22182504

In that case, use translate

translate(COMMENTS ,chr(13)||chr(10),'  ')   -- to replace CR or LF with a white space

Again, the important factor is that you don't use newlines as record delimiters. If you do, then this method will not work and you will most likely have to either modify the export process from Access or to do some preprocessing on the CSV file.

 

by: rowekPosted on 2008-08-07 at 09:23:56ID: 22182561

Okay, this may sound silly, but what is the best way to tell if that is the case?  use a hex editor to look at the file?  MS Access runs on Windows XP and creates a standard CSV text file.  If I do have NewLines what else can I do? The change must take place in this process as the export process cannot be changed. Thanks.  Testing now.

 

by: rowekPosted on 2008-08-07 at 10:32:53ID: 22183276

I just did extensive testing.   The text file is dependent on the CRLF at the end of each row to terminate the row.   Looks like the REPLACE and TRANSLATE will not work.  Is there another way to handle this INSIDE of the SQL*Loader Control file?  Thank you for your efforts so far.

 

by: gatorvipPosted on 2008-08-07 at 10:49:20ID: 22183437

To the best of my knowledge, no. What I've done in situations like this was to run a small app that would pre-process the file and remove the newlines inside the text field.

Can you completely bypass SQL loader and just write an app that connects to the Access database, pulls the data and inserts it into Oracle?

 

by: rowekPosted on 2008-08-07 at 10:54:28ID: 22183487

I would love to write that small app, but the situation has gone political and additional programming is not allowed.  If we could do it in the CTL file then that would be okay, but no new code.  The solution we decided on was to use an aliasing query on the export in order to replace the COMMENTS column contents with NULL.  Not elegant, but they do not really care about that column for their application.  I guess if there was a silver bullet they would go for it, but the project is out of funding and we need to close it out quickly.  
I did confirm with Visual Notepad++ that there are CRLFs at the end of each row and in the records that are getting thrown to the BAD file.

Thanks again for your help.

 

by: DrSQLPosted on 2008-08-07 at 11:48:00ID: 22184004

rowek,
   The problem is that SQL*Loader can't tell that you are still on the same row.  The CR/LF looks like a new row.  Try taking out the OPTIONALLY in the "OPTIONALLY ENCLOSED BY" and see if that allows it to scan multiple records.  I'll look and see if I can find an example of multiple physical records becoming one logical record.

Good luck!

 

by: DrSQLPosted on 2008-08-07 at 11:59:18ID: 22184123

rowek,
   OK, I think this is the right path.  Put the OPTIONALLY back in if you have any data not enclosed by quotes (like INSP_ID, I'm guessing).  The add this as the next line:

CONTINUEIF LAST PRESERVE != ''''

As long as the last column in the record is a string (and enclosed by a quote), I think this will work.  Here's where I got it from (10g, but not much changed in this area): http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_control_file.htm#i1005509

Good luck!

 

by: rowekPosted on 2008-08-07 at 14:36:52ID: 22185673

DrSQL: the politics have won out on this one.  We elected to drop to column, but I will do this...I will try your suggestion tomorrow and if it works I will award points.  I want to leave a solution.  gatorvip was very close but we needed the CRLF at the end of the steam.  Must run now...late for appt, but will try in the morning.  Thank you both for trying. Keith

 

by: awking00Posted on 2008-08-08 at 11:15:38ID: 22192264

Create a function to remove cr/lf, then only apply it to the comments column. See attached.

 

by: DrSQLPosted on 2008-08-08 at 11:20:22ID: 22192292

awking00,
    From what I gather, the problem is that the content of the data file might look like:

1,'FRED','I have only myself to blame.<CR>
<LF>If only I had looked right when I stepped off the curb on my visit to England.'

And SQL*Loader sees that as two records, when it should be one.  I could be wrong, but that's the problem I was trying to solve for rowek.

Good luck!

 

by: rowekPosted on 2008-08-08 at 11:23:32ID: 22192317

DrSQL, that's exactly the issue: rows are being "broken" sometimes two or three times.  Sorry I cannot test at the moment, must run payroll for my troops.  I hope to confirm your technique later today.  Cheers.

 

by: awking00Posted on 2008-08-08 at 11:28:14ID: 22192362

Thanks, DrSQL
Now, I see the problem. I gather it only gets worse if the comments data also contains commas.

 

by: rowekPosted on 2008-08-08 at 11:39:13ID: 22192456

awking00, do you still think your method is worth pursuing?  I did reveal your code and it appears to only strip out those characters for columns that I pass to it.  This means I would not harm the CRLF needed at the end of each row.  Will test after payroll run.

 

by: awking00Posted on 2008-08-08 at 12:00:36ID: 22192683

I would say it's worth a try.

 

by: rowekPosted on 2008-08-11 at 09:44:28ID: 22205951

My data has been changed.  The PM asked us to put a "NR" in the COMMENTS field so we could close out the project. If I can locate a copy of the old data (the one with the CRLFs in it) then I will see this thru.  Its important for me to know and for the other folks that are searching out a solution like I was.

Keith

 

by: gatorvipPosted on 2008-08-11 at 13:05:37ID: 22207694

>>CONTINUEIF LAST PRESERVE != ''''

This might work. Last year I tried to get it to run in an external table but was unable to do so, then I took a different approach.

>>Create a function to remove cr/lf, then only apply it to the comments column.

I don't think that's going to work, as by the time the COMMENTS field is passed to the function it has already been parsed in by the sql loader. If you test the function separately it will do it, of course, but not when it's invoked in the parfile.

>> Its important for me to know and for the other folks that are searching out a solution like I was.

I'm definitely interested to see if you're able to find a viable solution here.

 

by: rowekPosted on 2008-08-11 at 13:40:06ID: 22207990

I am out all this week for surgery...it may be a while.  Thank you both for trying hard.

 

by: rowekPosted on 2008-09-09 at 14:50:14ID: 22432665

Good news, I may be able to locate an old copy of the data and test out this suggestion:
<<<awking00:Create a function to remove cr/lf, then only apply it to the comments column.>>>
Will know in the morning. I want to know just as bad as you guys.  This is a real weakness of Oracle SQL*Loader, IMHO.

 

by: rowekPosted on 2008-09-16 at 05:59:16ID: 31484372

Thank you for your patience on this one, surgery had me down for a while.  I gave you  an excellent for effort.  The solution is partial.  It seems to work well when only one CRLF is found in the COMMENTS field.  If multiple CRLFs are found then I get "second enclosure string not present".  In the BAD file I see a double quote to start the string but no ending double quote.  Thank you again for the solution and the patience.  Keith

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...