Generating sequential months in oracle



create table natural_numbers(num1 number);

begin
for i in 1 .. 1000
loop
insert into natural_numbers values(i);
commit;
end loop;
end;

SELECT TO_CHAR(ADD_MONTHS('01-JAN-2005',ROWNUM-1),'MON-YYYY')
FROM natural_numbers
WHERE ADD_MONTHS('01-JAN-2005',ROWNUM-1)
BETWEEN '01-JAN-2004' AND '01-DEC-2005';

create public synonym natural_numbers for natural_numbers;
grant select on natural_numbers to allzone;

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post