Oracle SQL 查询:按 space 拆分字符串并获取第 n 个字符串

Oracle SQL query: Split string by space and get the nth string

我一直在 Whosebug 上搜索这个,但还没有找到答案。

给定字符串“hello my name is...”,我想将字符串拆分 spaces 并获取该字符串的第 n 个元素。

比如拆分后:[hello,my,name,is...] 第一个元素是“hello”,第二个元素是“my”,依此类推..

我的尝试:

SELECT REGEXP_SUBSTR(help, ' ', 1, 2) from 
(select 'hello my name is...' as help from dual);

这是不正确的,给我一个空的结果。我认为正则表达式 space.

有问题

你很接近。您只需要搜索 非空格 ,因为这就是您想要的 return:

select REGEXP_SUBSTR(help, '[^ ]+', 1, 2)
from (select 'hello my name is...' as help from dual);