-- 使用 REPLACE 函数替换字符串中的指定子字符串
-- 语法: REPLACE(str, from_str, to_str)
-- 参数:
-- str: 原始字符串
-- from_str: 要被替换的子字符串
-- to_str: 用来替换的新子字符串
-- 示例 1: 替换 'hello' 中的 'l' 为 'L'
SELECT REPLACE('hello', 'l', 'L');
-- 结果: 'heLLo'
-- 示例 2: 替换 'www.example.com' 中的 'example' 为 'test'
SELECT REPLACE('www.example.com', 'example', 'test');
-- 结果: 'www.test.com'
-- 示例 3: 如果 from_str 不存在于 str 中,则返回原始字符串
SELECT REPLACE('hello world', 'bye', 'hi');
-- 结果: 'hello world'
上一篇:mysql lower_case_table_names
下一篇:mysql 正则
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站