我想问我如何过滤可能包含2种模式的列“产品”:
例如:ABC1258,acb548796
例如:K123233_06565,K435_245 谢谢
答案 0 :(得分:1)
这里是一个使用正则表达式的选项。
SQL> with test (col) as
2 (select 'ABC1258' from dual union all
3 select 'K435_245' from dual union all
4 select 'AB_445' from dual union all
5 select 'KA234_23' from dual union all
6 select 'K12_BC' from dual union all
7 select 'XXX1243124YYY' from dual
8 )
9 select col
10 from test
11 where regexp_like(col, '^[[:alpha:]]{3}\d+$')
12 or regexp_like(col, '^K\d+_\d+$');
COL
-------------
ABC1258
K435_245
SQL>
答案 1 :(得分:0)
这也是一种实现方法:
with tab as(
select 'ABC1258' as str from dual union all
select 'abc548796'as str from dual union all
select 'K123233_06565'as str from dual union all
select 'K435_245'as str from dual union all
select 'X435_245'as str from dual union all
select 'A435_245'as str from dual union all
select 'KL435_245'as str from dual
)
select *
from tab
where REGEXP_LIKE (str, '^([A-Za-z]{3}[0-9]+)|(K[0-9]+_).*$');
结果:
ABC1258
abc548796
K123233_06565
K435_245