Page 1 of 1

Concatenate field value in replace() mysql

Posted: 12 May 2018, 07:41
by Marius
Hello,
How can I concatenate the value of a string in the replace() statement in mysql?

For example, in the 'content' column i have something like this:

Code: Select all

some content... {{$name_val}}
other text...
- The "name_val" is the value of the field 'name' in the same table.
I want to delete /replace all the '{{$name_val}}' sub-string from content, so, I need to apply Update with replace() statement with the value of the 'name' column.
But, how to add the value of the 'name' column in replace()?

Concatenate field value in replace() mysql

Posted: 12 May 2018, 07:45
by Admin
Hi,
You can use the concat() function in the replace() statement.

Code: Select all

REPLACE(col_name, concat('string',  col_2, 'join-string'), 'new_value')
- Here is an example:

Code: Select all

UPDATE table_name SET content = REPLACE(content, concat('{{$',  col_name, '}}'), 'new_value') WHERE id < 100