update CUST_BASIC_INFO set AgeGroup = 2 where
case
when length(card_no) = 18 then ---截取身份证年龄
ceil((to_char(sysdate, 'yyyyMMdd') -
to_char(to_date(substr(card_no, 7, 8), 'yyyy-MM-dd'),
'yyyyMMdd')) / 10000)
when length(card_no) = 15 then
ceil((to_char(sysdate, 'yyyyMMdd') -
to_char(to_date('19' || substr(card_no, 7, 6),
'yyyy-MM-dd'),
'yyyyMMdd')) / 10000)
when length(cu.card_no) != 18 and length(cu.card_no) != 15 and BIRTHDAY != null
then ceil((to_char(sysdate, 'yyyyMMdd') -
to_char(BIRTHDAY,
'yyyyMMdd')) / 10000)
end
in (select cu1.cuage from (select ---截取身份证年龄
case
when length(cu.card_no) = 18 then
ceil((to_char(sysdate, 'yyyyMMdd') -
to_char(to_date(substr(cu.card_no, 7, 8), 'yyyy-MM-dd'),
'yyyyMMdd')) / 10000)
when length(cu.card_no) = 15 then
ceil((to_char(sysdate, 'yyyyMMdd') -
to_char(to_date('19' || substr(cu.card_no, 7, 6),
'yyyy-MM-dd'),
'yyyyMMdd')) / 10000)
when length(cu.card_no) != 18 and length(cu.card_no) != 15 and BIRTHDAY != null
then ceil((to_char(sysdate, 'yyyyMMdd') -
to_char(BIRTHDAY,
'yyyyMMdd')) / 10000)
end as cuAge
from cust_basic_info cu)cu1 where cu1.cuage>=17 and cu1.cuage<=24)