| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

11-22-09, 20:55
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 3
|
|
|
how to replace quotes in db2 sql
|
|
the replace function cannot be used to replace single or double quotes. cna you let me know if there is any way to replace quotes with other character. thanks in advance
|
|

11-22-09, 21:09
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,196
|
|
|
|

11-22-09, 23:28
|
|
Registered User
|
|
Join Date: Jul 2009
Posts: 150
|
|
|
|
you have to use double quotes not a single...
Kara
|
|

11-23-09, 13:31
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
You can replace single or double quotes just fine. The only thing to remember is to use proper escaping. Escaping in SQL is to double the escaped character, i.e. a single quote inside a string is ''.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

11-23-09, 17:34
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 3
|
|
can i use the replace function in db2 to do that
|
|

11-23-09, 18:20
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
If this was a question, the answer is: yes, you can do that.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

11-24-09, 17:41
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 3
|
|
what about using regular expression in replace or translate function like can i use something like ^[A-Za-z0-9] if i want to replace anything other than alpha numeric.
Thanks
|
|

11-25-09, 09:03
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
|
|

02-15-12, 08:49
|
|
Registered User
|
|
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
|
|
Google found this old thread but the answer is not here. So here you go:
Code:
db2 "values replace(varchar('hoi''s'),x'27',space(1))"
The single quote will be replaced by a space
"hoi's" := "hoi s"
|
|

02-15-12, 08:55
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,196
|
|
Quote:
Originally Posted by dr_te_z
Google found this old thread but the answer is not here. So here you go:
Code:
db2 "values replace(varchar('hoi''s'),x'27',space(1))"
The single quote will be replaced by a space
"hoi's" := "hoi s"
|
How about this as I suggested over two years ago:
Code:
db2 "values replace(varchar('hoi''s'),x'27',x'20')"
1
-----
hoi s
1 record(s) selected.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
|
|

02-15-12, 14:36
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
Or if someone doesn't like to use ASCII code points:
Code:
replace(varchar('hoi''s'), '''', ' ')
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|