sql - 按模式返回具有逗号分隔值的行 (Oracle SQL)
问题描述
我有一些带有逗号分隔值的字段:
1,2,AA,4,Z
1,ZZ,44,A,1
1,44,33,AA,Z
4,2,Z,A,F
1.2,4,E,1,1
F,1,3.4,3,A
是否可以使用规则选择行:数字、数字、字符、任何值?
结果可以是:
1,2,AA,4,Z
4,2,Z,A,F
1.2,4,E,1,1
我正在尝试使用REGEXP_LIKE
:
with s as (
select '1,2,AA,4,Z' val from dual
union all
select '1,ZZ,44,A,1' val from dual
union all
select '1,44,33,AA,Z' val from dual
union all
select '4,2,Z,A,F' val from dual
union all
select '1.2,4,E,1,1' val from dual
union all
select 'F,1,3.4,3,A' val from dual
)
select val from s where REGEXP_LIKE(val, '(^|,)[[:digit:]](,|$)');
解决方案
'^([0-9.]*,)([0-9.]*,)([A-Z]+)'
如果您只想返回与模式匹配的行,这个正则表达式应该可以工作number, number, word, anything
select val from s where REGEXP_LIKE(val, '^([0-9.]*,)([0-9.]*,)([A-Z]+)');
推荐阅读
- android - 带有数据库触发器的 Firebase 云消息传递
- r - 将日期转换为特定格式,如月份、日期、年份
- drupal - 内容中的标题字段消失了
- c# - C# 将项目添加到列表
- java - 如何使用 JSSE 实现在 tomcat 8.5.5 中启用 TLSv1.3
- c# - C# .net 核心:具有相同 ID 的隐藏输入的多个 ajax 表单
- perl - goto 语句以及 if else 条件的问题
- python-requests - 当两者都需要不同的客户端证书时,如何使用 Python 请求通过代理连接到服务器
- docker - Docker Swarm 是否保持节点之间的数据同步?
- java - Appium iOS:每次测试前退出应用