Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove spaces from a data field during a query?

Status
Not open for further replies.

wjsullivan

Programmer
Aug 21, 2003
25
US
I've got a data field with all the states names (Illinois, New York, etc.). I need to use it in a query to build a URL, which requires me to be able to remove the spaces from the two word names.

Can I do this on the fly in my query? If so how?

Example of the delema:
SQL
' AS 'URL'

Results
For Illinois it works great

For New York it does not work at all
York.com/xxxx

How do I get rid of that space?
 
WJ,

First, in the Oracle/SQL*Plus World, your code will fail:
Code:
...'[URL unfurl="true"]https://www.'||STATENAME||'.com/xxxxxx'[/URL] AS 'URL'...
...because expression aliases (such as 'URL') must appear in double quotes: "URL".

You can achieve what you want by using either the Oracle "REPLACE" or Oracle "TRANSLATE" functions. I'll illustrate the code for both (when you want to "squeeze" certain characters out of a string, such as blank spaces in your case):
Code:
...'[URL unfurl="true"]https://www.'||replace(STATENAME,'[/URL] ',null)||'.com/xxxxxx' AS "URL"...

or

...'[URL unfurl="true"]https://www.'||translate(STATENAME,'x[/URL] ','x')||'.com/xxxxxx' AS "URL"...
Let us know your reactions to either of these methods.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top