我想问mysql中的locate()返回的是什么?
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函数
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`
mysql 截取指定的两个字符串之间的内容
今天我同事在用mysql的时候,需要对一个字符串中的指定内容进行截取
MySQL使用内置函数来进行模糊搜索(locate()等
MySQL使用内置函数来进行模糊搜索(locate()等) 常用的一共有4个方法,如下: 1. 使用locate()方法 1.1.普通用法: SELECT `column` from `table` where locate('keyword', `condition`)>0 类似于 java 的 indexOf();不过 locate() 只要找到返回的结果都大于0(即使是查询的内容就是最开始部分),没有查找到才返回0; ...
mysql基于正则实现模糊替换字符串的方法分析
主要介绍了mysql基于正则实现模糊替换字符串的方法,结合具体实例对比分析了使用正则实现mysql字符串替换的注意事项与相关操作技巧,需要的朋友可以参考下


