假如有一个表:
created table t
(
birthday date
)
里面有一个数据 1993-3-5
问下一个生日是什么时候?
------解决思路----------------------
感觉楼主的意思是下一个生日是指下一次过生日,不是下一年~~~
with tab(birthday) as
(select date '1990-04-18'from dual union all
select date '1989-11-30' from dual union all
select date '1991-09-10' from dual union all
select date '1992-12-31'from dual union all
select date '2000-12-12' from dual union all
select date '1990-10-29' from dual)
select birthday,
(case
when to_char(sysdate, 'yyyy')
------解决思路----------------------
to_char(birthday, 'mmdd') >=
to_char(sysdate, 'yyyymmdd') then
to_date(to_char(sysdate, 'yyyy')
------解决思路----------------------
to_char(birthday, 'mmdd'),
'yyyy-mm-dd')
else
add_months(to_date(to_char(sysdate, 'yyyy')
------解决思路----------------------
to_char(birthday, 'mmdd'),
'yyyy-mm-dd'),
12)
end) next_birthday
from tab;
------解决思路----------------------
select case when sysdate-trunc(sysdate,'Y')>t.birthday-trunc(t.birthday,'Y')
then add_months(t.birthday,(extract(year from (sysdate-t.rq) year to month)+1)*12)
else add_months(t.birthday,extract(year from (sysdate-t.rq) year to month)*12) end NextBirthday
from t;
------解决思路----------------------
-- 下次生日 ,用这个,简单一些。
SQL> create table test(birthday date) ;
Table created
SQL> begin
2 insert into test values(to_date('2013-09-03','yyyy-mm-dd'));
3 insert into test values(to_date('2013-10-03','yyyy-mm-dd'));
4 insert into test values(to_date('2013-11-03','yyyy-mm-dd'));
5 end ;
6 /
PL/SQL procedure successfully completed
SQL> select add_months(birthday , ceil(months_between(sysdate,birthday) / 12) * 12) x
2 from test ;
X
-----------
2016/9/3
2016/10/3
2015/11/3
SQL> drop table test purge ;
Table dropped
SQL>