oracle中怎样获取当前月上个月的第一天和最后一天?

查询数据时有个列T是月数据,包括8,9,10月的数据, 现在是10月 。请教一下如何对T列做限制,只查询9月的数据?

第1个回答  推荐于2017-10-01
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是个变化的量,不建议使用。本回答被提问者采纳