将表达式的后半部分仅匹配字母 SQL ORACLE
Match the end half of an expersion to only letters SQL ORACLE
我在 SQL table 中有一列数据,在第一次通过后它只包含以 'BVH' 和 'BVG' 开头的数据。我希望它只包含在此之后有 3 个数字字符且没有更多字母的数据。我试过了
OUC not like 'BVG%[a-z]%' and OUC not like 'BVH%[a-z]%'
因为我不知道这些字母是否会落在前 3 个字母之后的第一个、第二个或第三个(或多个)位置。我也不知道具体会出现什么字母
示例数据
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}');
我在 SQL table 中有一列数据,在第一次通过后它只包含以 'BVH' 和 'BVG' 开头的数据。我希望它只包含在此之后有 3 个数字字符且没有更多字母的数据。我试过了
OUC not like 'BVG%[a-z]%' and OUC not like 'BVH%[a-z]%'
因为我不知道这些字母是否会落在前 3 个字母之后的第一个、第二个或第三个(或多个)位置。我也不知道具体会出现什么字母
示例数据
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}');