DB2 提取两个定界符之间的数据

DB2 extract data between two delimiters

这是我试图从中提取的字符串: 'cn=xyxyxyxyxyx ousy,ou=information services,ou=domain users,dc=corp,dc=xyxyxx,dc=com'

我正在尝试提取第一个 'ou=' 和第二个逗号之间的字符串。在这种情况下 'information services'

这是我目前的情况: SUBSTR(F_DN, locate('ou=', F_DN)+3, locate(',', F_DN, locate(',', F_DN)+ 1)+1 ) 作为角色 这是结果: 'information services,ou=domain users,dc=co'

它似乎定位到第一个字符就好了,但我无法获得正确的长度。

试试这个:

select regexp_substr(str, 'ou=([^,]+)', 1, 1, '', 1)
from (values 'cn=xyxyxyxyxyx ousy,ou=information services,ou=domain users,dc=corp,dc=xyxyxx,dc=com') t (str);