sql – 使用空格和字符将字符串拆分为Oracle中的分隔符和regexp_
发布时间:2021-02-23 01:41:14 所属栏目:MsSql教程 来源:网络整理
导读:我正在尝试用regexp_subtr拆分字符串,但我无法使其工作. 所以,首先,我有这个查询 select regexp_substr('Helloworld - test!','[[:space:]]-[[:space:]]') from dual 非常好地提取我的分隔符 – 空白 但是,当我尝试使用此选项拆分字符串时,它只是不起作用.
我正在尝试用regexp_subtr拆分字符串,但我无法使其工作. 所以,首先,我有这个查询 select regexp_substr('Helloworld - test!','[[:space:]]-[[:space:]]') from dual 非常好地提取我的分隔符 – 空白 但是,当我尝试使用此选项拆分字符串时,它只是不起作用. select regexp_substr('Helloworld - test!','[^[[:space:]]-[[:space:]]]+')from dual 查询什么都不返回. 帮助将不胜感激! 解决方法SQL FiddleOracle 11g R2架构设置: CREATE TABLE TEST( str ) AS SELECT 'Hello world - test-test! - test' FROM DUAL UNION ALL SELECT 'Hello world2 - test2 - test-test2' FROM DUAL; 查询1: SELECT Str,COLUMN_VALUE AS Occurrence,REGEXP_SUBSTR( str,'(.*?)([[:space:]]-[[:space:]]|$)',1,COLUMN_VALUE,NULL,1 ) AS split_value FROM TEST,TABLE( CAST( MULTISET( SELECT LEVEL FROM DUAL CONNECT BY LEVEL < REGEXP_COUNT( str,'(.*?)([[:space:]]-[[:space:]]|$)' ) ) AS SYS.ODCINUMBERLIST ) ) Results: | STR | OCCURRENCE | SPLIT_VALUE | |-----------------------------------|------------|--------------| | Hello world - test-test! - test | 1 | Hello world | | Hello world - test-test! - test | 2 | test-test! | | Hello world - test-test! - test | 3 | test | | Hello world2 - test2 - test-test2 | 1 | Hello world2 | | Hello world2 - test2 - test-test2 | 2 | test2 | | Hello world2 - test2 - test-test2 | 3 | test-test2 | (编辑:源码网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐
热点阅读