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.

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Java Curious ღ
  • 3,102
  • 8
  • 34
  • 58

2 Answers2

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%';
Community
  • 1
  • 1
Praveen Prasannan
  • 6,802
  • 9
  • 45
  • 67
  • Shall I have to use `WHERE order_address LIKE '%sep%'` compulsory or not ? – Java Curious ღ Jan 31 '14 at 06:34
  • "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 – Praveen Prasannan Jan 31 '14 at 06:36
  • 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` – Java Curious ღ Jan 31 '14 at 06:36
  • http://stackoverflow.com/questions/14231278/error-error-code-1175-during-executing-update-command-on-table-using-mysql-wo – Praveen Prasannan Jan 31 '14 at 06:47
  • Whooa, great sir.. Query Solved. Thank You Praveen Sir. I have just Used set query your then update, it works. – Java Curious ღ Jan 31 '14 at 06:47
0

You may use REPLACE, like this:

UPDATE table1
SET order_address = REPLACE (order_address, 'sep', '//')
WHERE order_address LIKE '%sep%'
Aziz Shaikh
  • 15,104
  • 9
  • 55
  • 73