我的表在我的oracle数据库中看起来像这样;
ID | NI | NT | MB | ETC
-------------------------------------------
1 |1234567 | | | comments //valid
2 |9654875 | | | jhdsd //valid
3 |43gf543 | | | dd //in-valid
4 |123 | | | dfds //in-valid
5 |12654332 | | | dffd //in-valid
6 | |542 | | comments //valid
7 | |362 | | jhdsd //valid
8 | |9631 | | dd //invlaid
9 | |r45 | | dfds //in-valid
10 | |56 | | dffd // in-valid
11 | | |03121234567 | comments //valid
12 | | |03874514414 | jhdsd //valid
13 | | |05764544444 | dd //in-valid as not starts with 03
14 | | |30010101019 | dfds //in-valid
15 | | |038f5678543 | dffd //in-valid
我喜欢通过选择查询仅选择有效记录
其中
结果应如下所示;
1 |1234567 | | | comments
2 |9654875 | | | jhdsd
3 | |542 | | comments
4 | |362 | | jhdsd
5 | | |03121234567 | comments
6 | | |03874514414 | jhdsd
答案 0 :(得分:2)
尝试一下:
NI长度应固定为7,并且以任意数字开头
REGEXP_LIKE(NI, '^\d{7}$')
NT长度应固定为3,并且必须以任意数字开头
REGEXP_LIKE(NT, '^\d{3}$')
位数MB长度应固定为11,以03和所有数字开头。
REGEXP_LIKE(MB, '^03\d{9}$')
答案 1 :(得分:0)
您可以使用substr和length
select ID, NI, NT, MB, ETC
from my_table
where length(NI) = 7
and length(NT) = 3
and substr(MB,1,2) ='03'
AND REGEXP_LIKE(NI, '^[[:digit:]]+$')
AND REGEXP_LIKE(NT, '^[[:digit:]]+$')