-- 使用 LOCATE 函数查找字符串位置
-- 语法: LOCATE(substring, string [, position])
-- 参数:
-- substring: 要查找的子字符串
-- string: 原始字符串
-- position: 可选参数,指定从哪个位置开始查找,默认是1
-- 示例代码:
SELECT LOCATE('world', 'hello world') AS position;
-- 解释:
-- 这条 SQL 语句会在字符串 'hello world' 中查找子字符串 'world' 的位置。
-- 如果找到,返回子字符串的第一个字符在原始字符串中的位置(从1开始计数);
-- 如果找不到,返回0。
-- 输出结果将是:
-- +----------+
-- | position |
-- +----------+
-- | 7 |
-- +----------+
下一篇:mysql 性能优化
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站