Question

Syntax for using Trim, Ltrim, and Rtrim & sample of output

Asked by: sikyala

I have some data in an oracle table that I need to clean up.

Here is a sample of the data from a text file before it was loaded into an oracle table via sql loader (I have 10,774 records in the table):

|(1) NT-53556 NT53556|(10) Radar Signal Interpretation Using Neural Network for Defect Detection in Concrete,|(20) Shoukry, Samir N. Martinelli, David Varadarajan, Srinivas T. Halabe, Udaya B. |(11) 01 Mar 1996|(15) 5 Page(s) |(22) N--(U) ISSN 0025-5327, BRIDGES, CONCRETE, GROUND PENETRATING RADAR, INFRASTRUCTURE, NEURAL NETWORKS.; |(27) na|(14) JOURNAL ARTICLES |(12) NTIAC |(3) Unclassified

As you can see The columns are pipe delimited.

Here is what I need to do:

1. There are 19 columns. I need to delete the numbers that appear on the left of the text for example: (1) from each column. Each record of a column for example author column has the same number. So for every record of that column at the beginning the data in that column will begin with (20). Everything after the open parens, number and close parens I want to remain in that column.

2. I also need to delete all the white spaces that appear after the open parens, number and close parens.

3. In the first field delete duplicate information (NT-53556 NT53556). As you can see the data appears twice. The only difference is the data on the left has a hyphen in it. I want to delete the data on the right (i.e. data without hyphen)



Could someone please help me? Thanks!

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
2005-08-11 at 14:06:10ID21524392
Tags

oracle

,

trim

,

syntax

Topic

Oracle Product Info

Participating Experts
3
Points
500
Comments
14

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. Funny thing with the LTRIM function
    If you execute this select ltrim('17.7,0,18.4,13.2,24.5,0,17.4,6.9','17.7,0,18.4,13.2') from dual It returns the string '5,0,17.4,6.9'. Based on the definition of ltrim(str,[set]), it should remove all the characters up to the first character not in the set and should retu...
  2. LTRIM/RTRIM problem
    i've got a reporting procedure which i am trying to revise such that all the blank spaces are gone in between each of the returned attributes. like one of the fields, for example, orderno, is varchar(100), and often times it actually takes up about a 1/4 of that, so the repo...
  3. LTRIM(),RTRIM() functions won't work with ASP an…
    This is probably a cheap question for you experts but I have been trying to use the ltrim and rtrim functions to trim off spaces at both ends of a value (leading and trailing spaces) but I am not sure what I am doing wrong but I cannot get it to work. When I insert the TRIM ...
  4. RTRIM LTRIM for TEXT datatype
    Hi Experts, I am using a VARCHAR(MAX) parameter in one of the stored procedures. Recently i discovered it might get bigger than 8000 characters. So i changed that parameter to TEXT. But problem is i cannot use RTRIM, LTRIM functions on TEXT datatype. Is there any work aroun...
  5. VB.NET RTrim
    Dear Experts, In VB.NET, there is this function: String.Trim(array<Char>) which removes all leading and trailing occurrences of a set of characters specified in an array from the current String object. It looks like there are no RTrim and LTrim equivalents. I need ...

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: leoahmadPosted on 2005-08-11 at 18:10:21ID: 14657426

Your contrl file be:

LOAD DATA
   INFILE *
   INTO TABLE load_delimited_data
   FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '"'
   TRAILING NULLCOLS
   (  data1 "SUBSTR(DATA1,6,13)",
      data2 "SUBSTR(DATA2,6)",
      data3 "SUBSTR(DATA3,6)",
      data4 "SUBSTR(DATA3,6)",
.............
.............
   )
|(1) NT-53556 NT53556|(10) Radar Signal Interpretation Using Neural Network for Defect Detection in Concrete,|(20) Shoukry, Samir N. Martinelli, David Varadarajan, Srinivas T. Halabe, Udaya B. |(11) 01 Mar 1996|(15) 5 Page(s) |(22) N--(U) ISSN 0025-5327, BRIDGES, CONCRETE, GROUND PENETRATING RADAR, INFRASTRUCTURE, NEURAL NETWORKS.; |(27) na|(14) JOURNAL ARTICLES |(12) NTIAC |(3) Unclassified

 

by: sikyalaPosted on 2005-08-12 at 10:20:21ID: 14662773

I don't understand your response. I already created a control file and loaded the data into an oracle table. I am trying to remove whitespace and the numbers.

 

by: leoahmadPosted on 2005-08-12 at 10:46:38ID: 14663026

Well ok, then use substr to remove numbers and whitespace. If you post you query results for :SELECT * FROM your_table; we are much easily understand your problem.

 

by: DrSQLPosted on 2005-08-12 at 12:44:44ID: 14664122

sikyala,
   You need to do a little parsing, but it's pretty easy:

update yourtable
   set col1 = substr(col1, instr(col1,' ')+1, instr(col1, ' ', 1, 2) - instr(col1, ' ')),  -- this looks for the first space, then grabs everything from there to the next space
        col2 = substr(col1, instr(col1,' ')+1),  -- grab everything after the first space
        col3= <same as #2>

That should do it.

Good luck!
DrSQL

 

by: jignesh_oraclePosted on 2005-08-22 at 03:56:19ID: 14723049

Hi,

For case 1
you can very well use -
       Update <tablename>
       SET      field1 =  SUBSTR(field1,INSTR(field1,')',1)+1)

For case 2
you can use
       Update <tablename>
       SET      field1 =  TRIM(field1) -- This will remove white spaces from starting and ending of  
                                                       the string
For case 3
I am not clear for the requirement , What is the base of identifying duplication cause in example there is no consistency in the data, few record have no space in between and few has many.

I hope this will solve the problem

Cheers!!

JB

 

by: sikyalaPosted on 2005-08-22 at 13:22:04ID: 14728161

For case 3 a sample of the data in ACCENS_NUM field (Primary Key of the table) is as follows:

(1)     NT-53575     NT53575
(1)     NT-53574     NT53574
(1)     NT-53573     NT53573
(1)     NT-53572     NT53572

- I want to essentially delete (1)
- delete the white space after (1)
- delete the data that appears on right (for example: NT53575, NT53574 and so on) and the white space that appears before this information

Basically if I did a query of this field I want to see:

NT-53575
NT-53574
NT-53573
NT-53572

Thanks!

 

by: DrSQLPosted on 2005-08-22 at 17:19:59ID: 14729711

sikyala,


update yourtable
   set col1 = substr(ltrim(substr(col1, instr(col1,')')+1)),1,instr(ltrim(substr(col1, instr(col1,')')+1)),' ')-1)

Good luck!
DrSQL

 

by: jignesh_oraclePosted on 2005-08-23 at 01:33:03ID: 14731289

In that case I would advice you to use following function,

--------------------------
-- Author    - JB
-- Date       - 23-Aug-2005
-- Modified  -N.A.
-- Purpose  -
-- Remarks - I have assumed that we have fixed string Primary key i.e. of 8 Characters
-- Try using following function in SELECT statement first and passing argument as col1
--------------------------


CREATE OR REPLACE FUNCTION my_val (p_string        VARCHAR2)
RETURN VARCHAR2
IS
   v_var   VARCHAR2(100);
BEGIN
   IF SUBSTR(REPLACE(p_string,'-',''),1, 7) = SUBSTR(p_string,14,7)
   THEN
           v_var := SUBSTR(p_string,1, 8) ;
   ELSE
           v_var := p_string;
   END IF;
RETURN v_var;
END my_val;
/


For Col 1 and Col2 related queries should be executed first so extra space will be removed and then try this function OTHERWISE what I would suggest is user my previous comments for col1 and col2 in the above function and manipulate the data.

Cheers !!

JB

 

by: sikyalaPosted on 2005-08-23 at 09:10:27ID: 14734957

JB

I have found your instructions very helpful. I already used the code from case 1 and 2 to remove the number parens and white space on the left side of the data of the ACCENS_NUM field. So I just need to remove the duplicate information (i.e. the whitespace and data that appears on the right side of each row.

This is how the rows look now:

NT-53575     NT53575

I want to remove the white space and information that follows it.

example:

     NT53575

Looking at the responses I have received it isn't clear how I should do this. Thanks for your help.

sikyala

 

by: sikyalaPosted on 2005-08-23 at 09:19:00ID: 14735052

DrSQL

I tried the following code

col2 = substr(col1, instr(col1,' ')+1),  -- grab everything after the first space

and it removed all the data from the field. I don't think it should have done that because there is no white space before the data.

 

by: DrSQLPosted on 2005-08-23 at 09:42:49ID: 14735283

sikyala,
   After your clarification, I posted the following, please try this instead:

update yourtable
   set col1 = substr(ltrim(substr(col1, instr(col1,')')+1)),1,instr(ltrim(substr(col1, instr(col1,')')+1)),' ')-1)

Good luck!
DrSQL

P.S.  Here's a test I ran:

SQL> select substr(ltrim(substr(col1, instr(col1,')')+1)),1,instr(ltrim(substr(col1, instr(col1,')')+1)),' ')-1) from dual
SQL>  2  
SWL> ed
Wrote file afiedt.buf

  1* select substr(ltrim(substr(&&col1, instr(&&col1,')')+1)),1,instr(ltrim(substr(&&col1, instr(&&c
SQL> /
Enter value for col1: '(1)     NT-53575     NT53575'
old   1: select substr(ltrim(substr(&&col1, instr(&&col1,')')+1)),1,instr(ltrim(substr(&&col1, instr
new   1: select substr(ltrim(substr('(1)     NT-53575     NT53575', instr('(1)     NT-53575     NT53575',')

SUBSTR(L
--------
NT-53575

 

by: sikyalaPosted on 2005-08-23 at 10:48:22ID: 14735893

Thank you DrSQL it worked like a charm.

Sikyala

 

by: DrSQLPosted on 2005-08-23 at 11:06:45ID: 14736045

sikyala,
    You are welcome.  Please try to be careful in your selection of the accepted versus the assisted answer.  I'm not by any means complaining about the point split - JB's contribution seems deserving.  I just like to see the answer that gets used as the one that is accepted.  It makes it clearer for those who read the thread later.  And, if I'm mis-reading your last comment, I apologize.  Thanks.

Good luck!
DrSQL

 

by: sikyalaPosted on 2005-08-23 at 11:20:06ID: 14736187

The reason for the split is because it was a 3 part question. basically I asked for help with 3 solutions to modify the data (i.e. I numbered each item (see original message)). I used The accepted answer as solutions to 2 of the questions (as stated in my last message to JB ) and I used the assisted answer as a solution to the 3rd question (as stated in my last comment). I hope this makes sense.

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...