我是oracle的新手,我正在编写一个查询,我必须在上个月获取 我的问题:
create or replace function checkDuplicate(in_id in varchar2) return boolean is
begin
insert into tbl_log (id,"DATE") values(in_id , sysdate);
return true;
exception when dup_val_on_index then
return false;
end;
/
但它给了我
是当月的AUG。
我希望输出为上个月的JUL
我们怎样才能达到上个月的记录。
答案 0 :(得分: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