Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / May 2006

Tip: Looking for answers? Try searching our database.

translate function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mehmet Baserdem - 30 May 2006 20:00 GMT
Hi all,

I am trying to remove all blank chars in middle of the string "text1
text2   text3      text3 text4"

with following stmt:

VALUES(translate('text1  text2   text3      text3 text4'   ,   ''
,' '  ))

But it seems that the resulting string same with the input string.

1
-------------------------------------
text1  text2   text3      text3 text4

 1 record(s) selected.

Do you have any idea what is going on here?

FYI:

VALUES(translate('text1  text2   text3      text3 text4'   ,   '*'
,' '  ))  produces the

right output

1
-------------------------------------
text1**text2***text3******text3*text4

 1 record(s) selected.

Regards,

Mehmet Baserdem
4.spam@mail.ru - 31 May 2006 07:04 GMT
Hello.
Try this:
--
VALUES(replace('text1  text2   text3      text3 text4'   ,   ' ' ,''
))
--

Sincerely,
Mark B.

> I am trying to remove all blank chars in middle of the string "text1
> text2   text3      text3 text4"
[quoted text clipped - 3 lines]
> VALUES(translate('text1  text2   text3      text3 text4'   ,   ''
> ,' '  ))
Peri - 31 May 2006 10:57 GMT
Mehmet,
If trimming of white spaces is what is really intented, then replace is
the function you want to use.
Translate: Returns a transformed string expression & thus the length of
the return'd string would be same as the original.
Replace: replaces all the occurrences of expr1 in expr2 with expr3

For example:
DB2-CLP Prompt>db2 values "char(replace('text1  text2   text3
text3 text4',' ',''),25)"

1
-------------------------
text1text2text3text3text4

 1 record(s) selected.

> Hi all,
>
[quoted text clipped - 32 lines]
>
> Mehmet Baserdem
Mehmet Baserdem - 31 May 2006 15:35 GMT
Thanks Mark and Peri,

I was trying to trim the intermediate space chars.  It seems that
"Replace: function is getting the job done.

Regards,

Mehmet Baserdem
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.