我想问mysql中的locate()返回的是什么?

qrverwe2w qrverwe2w 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

DELIMITER //

create procedure request_info(client_id int, services varchar(20))
begin
declare comma_pos int;
declare current_id int;

svcs: loop
set comma_pos = locate(',', services);
set current_id = substr(services, 1, comma_pos);

if current_id <> 0 then
set services = substr(services, comma_pos+1);
else
set current_id = services;
end if;

insert into service_info values(null, client_id, current_id);

if comma_pos = 0 or current_id = '' then
leave svcs;
end if;
end loop;
end//

//
DELIMITER ;

call request_info("45", "1,4,6");



如题


数据库的数组下标究竟从1开始还是0开始,若以1开始那么locate(',', services)应该返回2吧?
...全文

相关推荐

MySQL中的LOCATE和POSITION函数使用方法

不常用:MySQL中的LOCATE和POSITION函数

weixin_38701156

MySQL高效模糊搜索之内置函数locate instr position find_in_set使用详解

常用的一共有4个方法,如下: 1.使用locate()方法 普通用法: SELECT`column`from`table`wherelocate('keyword',`condition`)>0 类似于java的indexOf(); 不过locate()只要找到返回的结果都大于0(即使是查询的内容就是最开始部分),没有查找到才返回0; 指定起始位置: SELECT LOCATE('bar','foobarbar',5);(从foobarbar的第五个位置开始查找) 2.使用instr()函数(据说是locate()的别名函数) SELECT `column` from `table`

weixin_38740201

mysql 截取指定的两个字符串之间的内容

今天我同事在用mysql的时候,需要对一个字符串中的指定内容进行截取

weixin_38641111

MySQL使用内置函数来进行模糊搜索(locate()等

MySQL使用内置函数来进行模糊搜索(locate()等) 常用的一共有4个方法,如下: 1. 使用locate()方法 1.1.普通用法: SELECT `column` from `table` where locate('keyword', `condition`)&gt;0 类似于 java 的 indexOf();不过 locate() 只要找到返回的结果都大于0(即使是查询的内容就是最开始部分),没有查找到才返回0; ...

小码农的

mysql基于正则实现模糊替换字符串的方法分析

主要介绍了mysql基于正则实现模糊替换字符串的方法,结合具体实例对比分析了使用正则实现mysql字符串替换的注意事项与相关操作技巧,需要的朋友可以参考下

weixin_38722052
评论 23
收藏 已收藏
分享
返回顶部
qrverwe2w
MySQL 57,063 成员 56,760 内容