2017-08-19 51 views
0

我新的Oracle和我寫一個查詢在那裏我上個月來獲取 我的查詢:如何才能實現上個月記錄在Oracle

select to_char(sysdate,'MON') from dual 

但它給我
AUG這是當前月份。
我想輸出爲上個月的JUL

我們如何才能實現上個月的記錄。

回答

3
select to_char(ADD_MONTHS (SYSDATE, -1),'MON') from dual 

--Move ahead one month: 
ADD_MONTHS (SYSDATE, 1); 

--Move backward 1 month: 
ADD_MONTHS (SYSDATE, -1); 

http://www.oracle.com/technetwork/issue-archive/2012/12-jan/o12plsql-1408561.html

Oracle數據庫爲被請求量移位日期 或找到一個日期提供了多種內置功能:

ADD_MONTHS—adds the specified number of months to or subtracts it from a date (or a timestamp) 
NEXT_DAY—returns the date of the first weekday named in the call to the function 
LAST_DAY—returns the date of the last day of the month of the specified date 
+0

感謝感激! –