Is there a function to eat extra spaces in a string?

All posts relating to Oracle PL/SQL development.

Moderator: Tim...

Is there a function to eat extra spaces in a string?

Postby mode09 » Thu Jan 31, 2013 7:03 pm

I know about rtrim, ltrim commands, but what I was interested in was a way to eat extra spaces also contained within strings.


For example:
myString = ' The dog is out side the house . ';

Is there a function that will keep one space between each word so the final result would be:
'The dog is outside the house.'
mode09
Member
 
Posts: 17
Joined: Wed Jul 16, 2008 3:19 pm

Re: Is there a function to eat extra spaces in a string?

Postby Tim... » Thu Jan 31, 2013 9:04 pm

Hi.

What about,

Code: Select all
Replace(variable, '  ', ' ')


If you think you might have more than two together, you could use regexp_replace.

Cheers

Tim...
Tim...
Oracle ACE Director
Oracle ACE of the Year 2006 - Oracle Magazine Editors Choice Awards
OakTable Member
OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
OCP Advanced PL/SQL Developer
Oracle Database: SQL Certified Expert
My website: http://www.oracle-base.com
My blog: http://www.oracle-base.com/blog
Tim...
Site Admin
 
Posts: 17935
Joined: Mon Nov 01, 2004 5:56 pm
Location: England, UK


Return to Oracle SQL and PL/SQL Development

Who is online

Users browsing this forum: No registered users and 6 guests