V
V
Vyacheslav Yashnikov2020-06-08 10:13:13
MySQL
Vyacheslav Yashnikov, 2020-06-08 10:13:13

How to replace a substring in a Mysql table with a randomly selected emoji from a list?

Good day!
There is a problem, in the database, when transferring, emoji were rubbed and changed to a question mark "?", there were emoji of the form: .
How to correctly compose a mysql query to replace a character ? in the field of the table on a randomly selected emoji from the list?

UPDATE `modx_site_content` SET `longtitle` = REPLACE(`longtitle`, ' ? ', '  ');


With one character, everything is clear, but with a random question from the list, please help.

Habr overwrites emoji in this regard, imagine that emoji corresponds to any letter of the alphabet, for example a, b, c, d, e, and you need to replace the question mark with spaces on the left and right with a letter from the list above

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nozzy, 2020-06-08
@VyacheslavY

UPDATE 
`modx_site_content` t1
SET t1.`longtitle` = REPLACE(`longtitle`, ' ? ', 
(
select t2.*
from 
(
  select 'a'
  union
  select 'b'
  union
  select 'c'
) t2
order by rand() limit 1
)
);

W
WinPooh32, 2020-06-08
@WinPooh32

changed to a question mark "?"

Because at some stage of the transfer, the characters were recoded into a different encoding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question