I'm unable to comment so I'll write new response
Thanks Prabhat, your code compiled fine but when i tried running the
proc , it threw error as : Error report - ORA-01858: a non-numeric
character was found where a numeric was expected ORA-06512: at
"GDWARC_JPN.MNTH_SNAPSHOT", line 9 ORA-06512: at line 1 01858. 00000 -
"a non-numeric character was found where a numeric was expected" Could
you please help.
Your problem is that you are using different data types.
SELECT (to_char(snapshot_period,'MON-yyyy')) BULK collect into snap_tab/*changed*/ FROM GDWARC_JPN.DIM_ORG_UNIT_HIST;
For start, you are using date, converting it to char and then saving it to date again. Don't know how can you even compile this
SELECT (to_char(trunc(sysdate, 'MM'), 'MON-yyyy')) INTO arg1 FROM dual;
When you convert sysdate to your desired format and save it to varchar variable, it's not date anymore. Then you are comparing it with a date and because you have your format on the date, it's not recognized.
So either use date in all variables and TRUNC option to extract only month and year from it (although I'm not sure you can cast members of table in member of, maybe you'll need to use for in that situation) or turn snap table to varchar type
EXAMPLE
CREATE OR REPLACE PROCEDURE MNTH_SNAPSHOT AS
arg1 varchar2(10) ;
TYPE snap IS TABLE OF varchar2(10);
snap_tab snap := snap() ; --declare a new collection variable and use this
BEGIN
SELECT (to_char(trunc(sysdate, 'MM'), 'MON-yyyy')) INTO arg1 FROM dual;
SELECT (to_char(snapshot_period,'MON-yyyy')) BULK collect into snap_tab/*changed*/ FROM GDWARC_JPN.DIM_ORG_UNIT_HIST; -- multiple values like DEC-2016, JAN-2016 etc . snapshot_period is date column
if arg1 member of snap_tab /*changed*/ then
execute immediate 'alter table GDWARC_JPN.DIM_ORG_UNIT_HIST truncate partition arg1';