實用的MySQL Function: Split String

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   |  +-------+

這個網誌中的熱門文章

Bash判斷參數是否存在

使用 minikube 輕鬆上手 kubernetes