1:定义存储过程,用于分隔字符串

DELIMITER $$USE `mess`$$DROP PROCEDURE IF EXISTS `splitString`$$CREATE DEFINER=`root`@`%` PROCEDURE `splitString`(IN f_string VARCHAR(1000),IN f_delimiter VARCHAR(5))BEGIN    DECLARE cnt INT DEFAULT 0;    DECLARE i INT DEFAULT 0;    SET cnt = func_get_splitStringTotal(f_string,f_delimiter);    DROP TABLE IF EXISTS `tmp_split`;    CREATE TEMPORARY TABLE `tmp_split` (`val_` VARCHAR(128) NOT NULL) DEFAULT CHARSET=utf8;    WHILE i < cnt    DO      SET i = i + 1;      INSERT INTO tmp_split(`val_`) VALUES (func_splitString(f_string,f_delimiter,i));    END WHILE;  END$$DELIMITER ;
REPLACE(str,from_str,to_str)Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE() performs a case-sensitive match when searching for from_str.例如:mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');    -> 'WwWwWw.mysql.com'
DELIMITER $$USE `mess`$$DROP FUNCTION IF EXISTS `func_get_splitStringTotal`$$CREATE DEFINER=`root`@`%` FUNCTION `func_get_splitStringTotal`(  f_string VARCHAR(10000),f_delimiter VARCHAR(50)  ) RETURNS INT(11)BEGIN   RETURN 1+(LENGTH(f_string) - LENGTH(REPLACE(f_string,f_delimiter,'')));  END$$DELIMITER ;
(1)REVERSE(str)Returns the string str with the order of the characters reversed.例如:mysql> SELECT REVERSE('abc');    -> 'cba'(2)SUBSTRING_INDEX(str,delim,count)Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.例如:mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);    -> 'www.mysql'mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);    -> 'mysql.com'
DELIMITER $$USE `mess`$$DROP FUNCTION IF EXISTS `func_splitString`$$CREATE DEFINER=`root`@`%` FUNCTION `func_splitString`( f_string VARCHAR(1000),f_delimiter VARCHAR(5),f_order INT) RETURNS VARCHAR(255) CHARSET utf8BEGIN    DECLARE result VARCHAR(255) DEFAULT '';    SET result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(f_string,f_delimiter,f_order)),f_delimiter,1));    RETURN result;  END$$DELIMITER ;

(1)调用存储过程:

CALL splitString('1,3,5,7,9',',');

(2):查看临时表

SELECT val_ FROM tmp_split AS t1;

结果:


更多相关文章

  1. ES6 变量声明,箭头函数,数组方法,解构赋值,JSON,类与继承,模块化练习
  2. 箭头函数的基础使用
  3. Python技巧匿名函数、回调函数和高阶函数
  4. 浅析android通过jni控制service服务程序的简易流程
  5. Android(安卓)bluetooth介绍(四): a2dp connect流程分析
  6. Android架构分析之使用自定义硬件抽象层(HAL)模块
  7. Android中OpenMax的适配层
  8. android 包管理系统分析
  9. Android中获取屏幕相关信息(屏幕大小,状态栏、标题栏高度)

随机推荐

  1. android 旋转动画
  2. Pro Andorid3第一章:Android平台简介
  3. System Server 分析
  4. cocos2d-x的win32工程移植到Android
  5. Android程序中如何执行shell脚本
  6. 【layout_weight权重】Android(安卓)对La
  7. Android Gradle Plugin指南(一)——简介 -
  8. Android之Android的数据存储--File
  9. android IPC及原理简介
  10. Android 中的WiFi学习笔记