In an Oracle database, we have created 22 materialized views and we have created a procedure to refresh all these MV’s. All 22 materialized views refresh successfully.
On the last day of every month, we wanted to refresh the materialized views and copy the data to historical tables. These historical tables have the same structure along with three additional columns that contain the date the data was copied along with the month and year that the data represents.
copy_datewill be thesysdatewhen the data is copied to history tablemonthandyearwill be passed in to the stored procedure.
For example, if I forgot to refresh at the end of January and remembered on February 4
copy_date: 4th of feb- ‘month’ and ‘year’ are : FEB and 2012
The reporting team will use these columns to filter the data in order to analyze it.
example : Table A
study country state
abc india ap
bcd china xx
I need a procedure that copies the data to a history table like:
month year copy_date study country state
jan 2013 01-01-2013 abc india ap
When I run this procedure, I want to enter values for the month and year parameters (jan and 2013 in this case).
First, I’m not sure why you would bother passing in the
monthandyearparameters rather than simply deriving that from thesysdate. In your example, you themonthandyearare based on the currentsysdatewhether you copy the data on January 30 or February 4.One option would be
You could also use dynamic SQL to avoid having to create 22 separate stored procedures. If the history tables always have the
month,year, andcopy_dateas their first three columns and have the remaining columns in exactly the same order as the base table