Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 10th, 2003, 09:30 AM
krishd krishd is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 krishd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PL/SQL data formatting

Hello!

I am trying to develop a PL/SQL function to perform some data cleansing. One of the data cleansing requirements is If there are instances of more than 1 space together, the extra spaces should be removed.

Say for example, if my data comes in as "123 456 789", then my function should clean it as "123 456 789" replacing multiple spaces with just 1 space.

What PL/SQL functions could I use to accomplish this?

Thanks
Krish

Reply With Quote
  #2  
Old September 10th, 2003, 10:31 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 28 m 41 sec
Reputation Power: 19
Re: PL/SQL data formatting

Quote:
Originally posted by krishd
Hello!

I am trying to develop a PL/SQL function to perform some data cleansing. One of the data cleansing requirements is If there are instances of more than 1 space together, the extra spaces should be removed.

Say for example, if my data comes in as "123 456 789", then my function should clean it as "123 456 789" replacing multiple spaces with just 1 space.

What PL/SQL functions could I use to accomplish this?

Thanks
Krish


replace, loop replacing double space with single untill no more replaces are made.

Reply With Quote
  #3  
Old September 10th, 2003, 11:25 AM
krishd krishd is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 krishd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks. But how do I determine if there are no more replaces. I'd appreciate it if you could you send me sample code, as I am new to PL/SQL.

Krish

Reply With Quote
  #4  
Old September 10th, 2003, 11:49 AM
krishd krishd is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 krishd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well...Did it the hard way. I wrote code to go through the data character by character and remove extra spaces.

Krish

Reply With Quote
  #5  
Old October 17th, 2003, 08:29 AM
abrowning abrowning is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 4 abrowning User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
5 replaces should deal with almost all (haven't fully checked out the math) occurances of multiple spaces and replace with a single space. The inner replace matches for 5 spaces, next one 4 spaces, 3 spaces, 2 spaces, 2 spaces. e.g

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(:value_with_spaces)), ' ', ' '),' ', ' '), ' ', ' '), ' ', ' '), ' ', ' ')

(the trims aren't necessary but remove any leading or trailing spaces)
This deals with every number of spaces I've tried it with, but as I said I'm no mathematician.

Andrew

Reply With Quote
  #6  
Old October 17th, 2003, 08:30 AM
abrowning abrowning is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 4 abrowning User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
the posting prog removed my double spaces from the above example!!
The numbers in the description are how many spaces should be in each one.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > PL/SQL data formatting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway