[英]Match the end half of an expersion to only letters SQL ORACLE
我在SQL表中有一列数据,并且在第一次传递之后,它仅包含以'BVH'和'BVG'开头的数据。 我希望它仅包含此后具有3个数字字符且没有更多字母的数据。 我努力了
OUC not like 'BVG%[a-z]%' and OUC not like 'BVH%[a-z]%'
因为我不知道字母是否会落在前三个字母之后的第一,第二或第三(或多个)位置。 我也不知道到底会出现什么字母
示例数据
BVH122
BVH174
BVH336
BVH123
BVH447
BVH447
BVH321
BVH573
BVG1NS
BVG1T2
BVH283
BVH172
BVG12T
BVG1T2
那是你需要的吗?
with dat as (select 'BVH122' a from dual
union all select 'BVH174' a from dual
union all select 'BVG1NS' a from dual
union all select 'BVH172' a from dual
union all select 'BVG12T' a from dual
)
select * from dat where regexp_like(a,'[A-Z]{3}[0-9]{3}');
因此,您的查询是:
select * from table where regexp_like(OUC,'BV[GH]{1}[0-9]{3}');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.