-- 使用 REPLACE 函数替换字符串
UPDATE table_name
SET column_name = REPLACE(column_name, 'old_string', 'new_string')
WHERE condition;
-- 示例:
-- 将表 `employees` 中 `email` 列中的所有 "@oldcompany.com" 替换为 "@newcompany.com"
UPDATE employees
SET email = REPLACE(email, '@oldcompany.com', '@newcompany.com');
-- 解释:
-- 1. REPLACE 是 MySQL 内置的字符串函数,用于将指定字符串中的子字符串替换为另一个字符串。
-- 2. UPDATE 语句用于更新表中的数据。
-- 3. 在这个例子中,我们将 `employees` 表中 `email` 列的所有 "@oldcompany.com" 替换为 "@newcompany.com"。
-- 4. WHERE 子句可以根据需要添加条件,以限制更新的行。
上一篇:mysql 拼接字段
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站