对码当歌,猿生几何?

oracle to_number函数 统计近三年的数据

select b.myear,a.org_name orgName,count(a.org_id)
    memberCount from
    (select m.* from
    (select
    org.org_id,org.org_name,org.last_org,poor.in_poortime,poor.out_poortime
    from pb_org org,pb_member pm,pb_poor_member poor
    where
    poor.member_id=pm.member_id
    and pm.org_id=org.org_id) m) a,
    (select to_number(to_char(sysdate,'yyyy')) myear
    from dual
    union
    select to_number(to_char(sysdate,'yyyy'))-1 myear from
    dual
    union
    select to_number(to_char(sysdate,'yyyy'))-2 myear from dual)
    b where b.myear>=substr(a.in_poortime,'1','4') and
    b.myear<=nvl(substr(a.out_poortime,'1','4'),to_char(sysdate,'yyyy'))
    group by b.myear,a.org_name
    order by b.myear desc

to_number根据生日统计年龄

((to_number(substr(to_char(sysdate,'yyyy-mm-dd'),1,4)) -
		to_number(substr(BIRTH_DATE,1,4)))) age,


阅读更多