Today I wrote a script that would take the values I had from my Calendar table, which contained all months with their start date and end date for the year of 2008, and insert them back for the year of 2007. My first solution didn't work so well and threw an error. I came to learn that the TO_YMINTERVAL function doesn't work because it doesn't handle leap year.
The function that did the job right was ADD_MONTH.
Here goes my script:
INSERT INTO calendar
(calendar_id,
month,
full_month,
begin_date,
end_date)
SELECT calendar_s1.nextval,
month,
full_month,
add_months(begin_date,-12),
add_months(end_date,-12)
FROM calendar;
Try that out and let me know if you have other simpler solutions for a similar problem.
Tuesday, May 27, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment