I want to insert some data into a table associated with dates for the next year. I actually only need workdays inserted.
BEGIN
FOR i IN 1..365 LOOP
INSERT INTO MY_TABLE (ID, MY_DATE)
VALUES (i, (to_date(sysdate,'DD-MON-YY')-1)+i);
END LOOP;
END;
I can solve my problem by going back and deleting rows that are weekend days, but that seems rather inelegant – can anyone think of a way to modify my loop so that it skips weekends?
You could always check the day of the week before inserting the row (the names of the days of the week will depend on your NLS settings so this isn’t the most robust solution possible)