Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a word in BLOB text by MySQL

I've got a huge mysql table (called tcountriesnew) and a column (called slogen, blob type). In each of those slogen blobs I'd like to replace a word, for example: banana to apple.

Unfortunately I tried to print all the rows with word banana, and it did not work.

select * from tcountriesnew where slogen like '%banana%';

Please help me.

  • What i missed, what is the problem with my query?
  • How can i replace text in blob?
like image 598
Répás Avatar asked Oct 19 '10 07:10

Répás


1 Answers

Depends what you mean by "replace"; using replace to show modified text in select:

select replace(slogen, 'bananas', 'apples') from tcountriesnew where slogen like '%bananas%';

Or update data in a table:

update tcountriesnew set slogen=replace(slogen, 'bananas', 'apples') where slogen like '%bananas%';

BTW. Why are you using blob for text? You should use text type for textual data and blob for binary data.

like image 169
Nux Avatar answered Oct 09 '22 15:10

Nux