【发布时间】:2015-10-17 17:11:44
【问题描述】:
我正在尝试使用 regexp_subtr 拆分字符串,但无法使其正常工作。
所以,首先,我有这个查询
select regexp_substr('Helloworld - test!' ,'[[:space:]]-[[:space:]]') from dual
很好地提取了我的分隔符 - blank-blank
但是,当我尝试使用此选项拆分字符串时,它就不起作用了。
select regexp_substr('Helloworld - test!' ,'[^[[:space:]]-[[:space:]]]+')from dual
查询不返回任何内容。
我们将不胜感激! 谢谢
【问题讨论】:
-
你的预期输出是什么?只有分隔符?
-
嗯,结果应该是“Helloworld”。但重要的是分隔符将是“ - ”,因为我想用“select regexp_substr('Helloworld - test!','[^[[:space:]]-[[ :space:]]]+',1,2)"
-
哎呀抱歉..我没有动静。你想得到分隔符之前的值还是分隔符之后的值??
-
好的,所以我有这个查询,以及我想要的结果。 "select regexp_substr('Helloworld - test!' ,'[^[[:space:]]-[[:space:]]]+'), select regexp_substr('Helloworld - test!' ,'[^[[: space:]]-[[:space:]]]+',1,2) from dual”,结果应该是“Helloworld”作为第 1 列,“test”作为第 2 列。我的问题是我不知道如何将分隔符设置为“空格 - 空格”。如果我只使用“-”,它就可以完美地工作,但我真的需要“空格”作为分隔符。例如“select regexp_substr('Helloworld - test!','[^-]+')from dual”工作得很好,但我想在分隔符中添加空格(空白)
标签: sql regex oracle string-split regexp-substr