I am trying to do a counter in an insert statment, where the counter will be turned into a month, then if the month is greater than 09, put it in year 2004, if <= 09, then put it as year 2005. Oh, and just for fun, to make it that last day of that particular month using LAST_DAY. Does this sound plausible? I am not a sql programmer but gave it a stab, if someone could look at the bloody mess and maybe just give me guidance (and don't laugh) then I would greatly appreciate it. Here goes :
BEGIN
INSERT INTO STG_AIRSPEED_PLN_METRICS_COMPL (
RECORD_NB,
TW_PLAN_CD,
SITE_CD,
MONTH_END_DT,
AS_OF_DT)
VALUES (
RECORD_NB_SEQ.nextval,
TW.TW_PLAN_CD,
TW.Site_cd,
(BEGIN
FOR M_counter in 1..12
LOOP
IF (M_Counter > 9)
THEN
LAST_DAY(TO_DATE(TO_CHAR(M_counter 01 2004, 'M DD YYYY') 'MM-DD-YYYY'))
ELSE
LAST_DAY(TO_DATE(TO_CHAR(M_counter 01 2005, 'M DD YYYY') 'MM-DD-YYYY'));
END LOOP
,
SYSDATE);
END;
Thanks for any help, time and knowledge!
Va
BEGIN
INSERT INTO STG_AIRSPEED_PLN_METRICS_COMPL (
RECORD_NB,
TW_PLAN_CD,
SITE_CD,
MONTH_END_DT,
AS_OF_DT)
VALUES (
RECORD_NB_SEQ.nextval,
TW.TW_PLAN_CD,
TW.Site_cd,
(BEGIN
FOR M_counter in 1..12
LOOP
IF (M_Counter > 9)
THEN
LAST_DAY(TO_DATE(TO_CHAR(M_counter 01 2004, 'M DD YYYY') 'MM-DD-YYYY'))
ELSE
LAST_DAY(TO_DATE(TO_CHAR(M_counter 01 2005, 'M DD YYYY') 'MM-DD-YYYY'));
END LOOP
SYSDATE);
END;
Thanks for any help, time and knowledge!
Va