mysql adds specified prefix and suffix to a field

Assume that you need to add the prefix "prefix_" and the suffix "_suffix" to field field1, you can use the following SQL statement:

UPDATE table_name SET field1 = CONCAT('prefix_', field1, '_suffix');


Among them, "table_name" is the table name, and "field1" is the specified field name. This statement will add prefixes and suffixes to the field1 field of all records in the specified table.

If you only want to add prefixes and suffixes to records with specified conditions, you can add a WHERE clause, for example:

UPDATE table_name SET field1 = CONCAT('prefix_', field1, '_suffix') WHERE some_column = some_value;


Among them, "some_column" is the column name of a certain condition column, and "some_value" is the value that the condition column needs to satisfy. This statement will only add prefixes and suffixes to records that meet the conditions.

Guess you like

Origin blog.csdn.net/u010522644/article/details/130103065