oracle add_months函數(shù)的用法詳解
如果需要取上一個(gè)月的數(shù)據(jù),并且每天都要進(jìn)行此操作,每次都需要改時(shí)間,的確非常的麻煩,所以想到了oracle add_months函數(shù)這個(gè)函數(shù)
oracle add_months函數(shù):
oracle add_months(time,months)函數(shù)可以得到某一時(shí)間之前或之后n個(gè)月的時(shí)間
- 如 select add_months(sysdate,-6) from dual;
該查詢的結(jié)果是當(dāng)前時(shí)間半年前的時(shí)間
- select add_months(sysdate,6) from dual;
該查詢的結(jié)果是當(dāng)前時(shí)間半年后的時(shí)間
- my examle:
- select distinct(t.mobile) from twaplogon t where to_char(t.logontime,'yyyy-mm')=to_char(add_months(sysdate,-1),'yyyy-mm')
以上就是oracle add_months函數(shù)的使用方法。
【編輯推薦】