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.

 
Go Back  dBforums > Database Server Software > MySQL > Replacing a single character

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-04, 17:26
djlerman djlerman is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
Replacing a single character

I have fields that have a bunch of characters I want to replace. How would I do that with an SQL statement. I could do this PERL but I wanted to hold off to see if I could do it directly in SQL first.

The Characters are:
CHR(12) with space
^ with '
CHR(145) with '
CHR(146) with '
etc.....
Reply With Quote
  #2 (permalink)  
Old 06-04-04, 17:29
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Quote:
Originally Posted by djlerman
I have fields that have a bunch of characters I want to replace. How would I do that with an SQL statement. I could do this PERL but I wanted to hold off to see if I could do it directly in SQL first.

The Characters are:
CHR(12) with space
^ with '
CHR(145) with '
CHR(146) with '
etc.....
Use Perl! A simple tr/// is much easier than the shenanigans you'll have to perform to simulate it using SQL!

-PatP
Reply With Quote
  #3 (permalink)  
Old 06-08-04, 15:55
Leaden Leaden is offline
Registered User
 
Join Date: Dec 2003
Location: Houston, TX
Posts: 21
You declared "shenanigans" eheheh
__________________
I do not fear computers. I fear the lack of them.
-Isaac Asimov (1920 - 1992)
Reply With Quote
  #4 (permalink)  
Old 06-15-04, 12:20
djlerman djlerman is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
O.K I figured it out (with the help of blogbarter.com). For any others out there that may need it. Here is the SQL statement to replace a single character:

Code:
update tablename set field = replace(field,'search','replace');
or for ASCII Code:

Code:
update tablename set field = replace(field,char(012),char(032));
Here is the link:
http://analogduck.com/blog/modules/n...hp?storyid=179

Last edited by djlerman; 06-15-04 at 12:22.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On