0

I have table like this :

enter image description here

In that order_address field is there.

In that I have stored details of buyer / user i.e. Name + address + City + Pin /Zip Code + State + Country + mobile.

Between All that I have used sep as separator of each one. Now I want to replace all sep with some other character in whole table.

Suppose I want to replace sep with // in whole table.

So how to do that using query? I don't know about it so any suggestion for that.

2
  • Just a comment - why to use MySQL if it's commercially super expensive? Now I moved to JavaDB - also the syntax is a little bit different.. Commented Jan 31, 2014 at 6:38
  • @ErnestasGruodis - Okay good idea, will follow from next project. But any suggestion for above query. Commented Jan 31, 2014 at 6:41

2 Answers 2

2

See Mysql string replace

SET SQL_SAFE_UPDATES=0;

Set SQL_SAFE_UPDATE mode

Update order_table 
set order_address = REPLACE(order_address , 'sep', '//')
WHERE order_address LIKE '%sep%';
Sign up to request clarification or add additional context in comments.

5 Comments

Shall I have to use WHERE order_address LIKE '%sep%' compulsory or not ?
"You don't necessarily have to add the WHERE LIKE clause at the end, because if the text to find isn't there the row won't be updated, but it should speed things up." – gmaggio
If i ll use above query it gives me an error 12:05:29 Update b2b.order_master set order_address = REPLACE(order_address , 'sep', '//') WHERE order_address LIKE '%sep%' Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect. 0.046 sec
Whooa, great sir.. Query Solved. Thank You Praveen Sir. I have just Used set query your then update, it works.
0

You may use REPLACE, like this:

UPDATE table1
SET order_address = REPLACE (order_address, 'sep', '//')
WHERE order_address LIKE '%sep%'

3 Comments

Shall I have to use WHERE order_address LIKE '%sep%' compulsory or not ?
@JavaCuriousღ no, not compulsory. May improve the performance though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.