字符串处理func_split,func_split_TotalLength
来源:互联网 发布:python 矩阵相乘 编辑:程序博客网 时间:2024/06/06 05:56
举例: 将字符串:‘abc,abcd,abcde,abcdef' 以',' 分割 取出第几个字符。
CREATE FUNCTION `func_split`(`f_string` text character set utf8 ,`f_delimiter` varchar(5),`f_order` int)
RETURNS varchar(9999)
BEGIN
DECLARE result VARCHAR(9999) character set utf8 default '';
set result=REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(f_string,f_delimiter,f_order)),f_delimiter,1));
RETURN result;
END ;
select func_split('a,ab,abc,abcd,abcde,abcdef',',',3);
abc;
select func_split('a|ab|abc|abcd|abcde|abcdef','|',4);
abcd;
CREATE DEFINER = `zkf`@`localhost` FUNCTION `func_split_TotalLength`(`f_string` text character set utf8 ,`f_delimiter` varchar(5))
RETURNS int(11)
BEGIN
RETURN 1+(LENGTH(f_string)-LENGTH(replace(f_string,f_delimiter,'')));
END ;
RETURNS int(11)
BEGIN
RETURN 1+(LENGTH(f_string)-LENGTH(replace(f_string,f_delimiter,'')));
END ;
select func_split_TotalLength('a,ab,abc,abcd,abcde,abcdef',',');
6;
select func_split_TotalLength('a|ab|abc|abcd|abcde','|');
5;
通常嵌套再循环中使用对每个结果操作。如下:
CREATE PROCEDURE `D_AUTHORITY`(IN `d_authority_id` varchar(20000),IN `controlParameter` varchar(8888))
BEGIN
DECLARE cnt int DEFAULT 0;
DECLARE i int DEFAULT 0;
set cnt=func_split_TotalLength(d_authority_id,',');
while i < cnt
do
set i=i+1;
update db_role r
set r.authority_ids = replace(r.authority_ids,CONCAT(func_split(d_authority_id,',',i),','),'');
update db_role r
set r.authority_ids = replace(r.authority_ids,CONCAT(',',func_split(d_authority_id,',',i)),'');
update db_authority a
set a.delete_authority = '1' where a.authority_id=func_split(d_authority_id,',',i);
BEGIN
DECLARE cnt int DEFAULT 0;
DECLARE i int DEFAULT 0;
set cnt=func_split_TotalLength(d_authority_id,',');
while i < cnt
do
set i=i+1;
update db_role r
set r.authority_ids = replace(r.authority_ids,CONCAT(func_split(d_authority_id,',',i),','),'');
update db_role r
set r.authority_ids = replace(r.authority_ids,CONCAT(',',func_split(d_authority_id,',',i)),'');
update db_authority a
set a.delete_authority = '1' where a.authority_id=func_split(d_authority_id,',',i);
end WHILE;
END;
END;
阅读全文
0 0
- 字符串处理func_split,func_split_TotalLength
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 处理字符串
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- jQuery常用方法
- tomcat中的server.xml文件配置了URIEncoding="UTF-8"需要注意的问题
- 【HDU 2087】剪花布条 【KMP or strstr函数】
- Tr A
- 【笔记篇】C#笔记3
- 字符串处理func_split,func_split_TotalLength
- TensorFlow从入门到实战资料汇总
- html获取url参数
- JavaScript sort() 方法详解
- DeepLearning Trick
- 启动WebLogic时提示:此时不应有\java\jdk1.8.0_144\lib\dt.jar;
- mysql忘记数据库的root密码解决办法
- 第七次多校联合hdu6127
- 暑假很糟糕