oracle如何获取每个月的最后一天

如题所述

第1个回答  2016-11-12
select trunc(add_months(sysdate,-1),'mm') first_day,last_day(add_months(sysdate,-1)) last_day from dual;
你的查询应该这样写:
select * from tabname where t between to_date('20130901','yyyymmdd') and to_date('20130930','yyyymmdd');
不建议在查询条件中写入变量,如
select * from tabname where t between trunc(add_months(sysdate,-1),'mm') and last_day(add_months(sysdate,-1));
这其中sysdate是个变化的量,不建议使用。本回答被网友采纳
第2个回答  2020-04-16
Select TRUNC(add_months(sysdate,+1),'mm')-1 from daul;