MySQL Split String Function
来源:互联网 发布:淘宝一键复制怎么用 编辑:程序博客网 时间:2024/05/18 03:48
MySQL does not include a function to split a delimited string. However, it’s very easy to create your own function.
Create function syntax
A user-defined function is a way to extend MySQL with a new function that works like a native MySQL function.
CREATE [AGGREGATE] FUNCTION function_nameRETURNS {STRING|INTEGER|REAL|DECIMAL}To create a function, you must have the INSERT privilege for the <mysql> database.
Split delimited strings
The following example function takes 3 parameters, performs an operation using an SQL function, and returns the result.
Function
CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT)RETURNS VARCHAR(255)RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, '');Usage
SELECT SPLIT_STR(string, delimiter, position)Example
SELECT SPLIT_STR('a|bb|ccc|dd', '|', 3) as third;+-------+| third |+-------+| ccc |+-------+
0 0
- MySQL Split String Function
- The Split Function -- use for std::string
- A SQL Function which used to split string by char
- stringutils.split string.split
- String#split
- String split()
- String.split()
- String.split
- String split()
- String.split()
- String.split
- String split
- String .split
- string.split
- String.split
- String split()
- String.split()
- String.split
- 【高精度算法】A*B 加强版
- 织梦tag标签显示每个标签相应的文章数量的方法
- C#写入和读出文本文件
- Core Animation 之 CALayer
- hdu 2309 ICPC Score Totalizer Software
- MySQL Split String Function
- android,去掉标题栏+++全屏显示
- Android 通过ViewPager实现广告轮播效果
- 【高精度算法】A+B
- 在TableLayout中使用TableRow对象来定义多行
- 以CSDN之父之名,欢迎自己
- php学习第二天:代码重构
- Linux命令下连接和搭建PPTPD-VPN
- Oracle数据库恢复案例