split_part

description

Syntax

VARCHAR split_part(VARCHAR content, VARCHAR delimiter, INT field)

根据分割符拆分字符串, 返回指定的分割部分(从一开始计数)。

example

  1. mysql> select split_part("hello world", " ", 1);
  2. +----------------------------------+
  3. | split_part('hello world', ' ', 1) |
  4. +----------------------------------+
  5. | hello |
  6. +----------------------------------+
  7. mysql> select split_part("hello world", " ", 2);
  8. +----------------------------------+
  9. | split_part('hello world', ' ', 2) |
  10. +----------------------------------+
  11. | world |
  12. +----------------------------------+
  13. mysql> select split_part("2019年7月8号", "月", 1);
  14. +-----------------------------------------+
  15. | split_part('2019年7月8号', '月', 1) |
  16. +-----------------------------------------+
  17. | 20197 |
  18. +-----------------------------------------+
  19. mysql> select split_part("abca", "a", 1);
  20. +----------------------------+
  21. | split_part('abca', 'a', 1) |
  22. +----------------------------+
  23. | |
  24. +----------------------------+

keywords

  1. SPLIT_PART,SPLIT,PART