How to change multiple records of an sql table at once?

Asked

Viewed 668 times

3

Imagine a result of an SQL:

ID - NOME- MENSAGEM

1 / israel / msg-olamundo
2 / rafael / msg-olamundo
3 / augusto / msg-olamundo

Now I want to do in SQL the same thing that str_replace would do in php take all records of an x the word "msg-".

Researching I found the answer and wanted to put here to help the crowd is very easy!

1 answer

4

update tabela
   set mensagem = REPLACE(mensagem, 'msg-', 'NOVO TEXTO AQUI OU DEIXAR VAZIO PARA APAGAR') 
 where `mensagem` LIKE '%msg-%'
  • Boy, thanks for sharing, saved here...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.