Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:34:10+00:00 2026-06-18T10:34:10+00:00

In an Oracle database, we have created 22 materialized views and we have created

  • 0

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_date will be the sysdate when the data is copied to history table
  • month and year will 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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:34:12+00:00Added an answer on June 18, 2026 at 10:34 am

    First, I’m not sure why you would bother passing in the month and year parameters rather than simply deriving that from the sysdate. In your example, you the month and year are based on the current sysdate whether you copy the data on January 30 or February 4.

    One option would be

    CREATE OR REPLACE PROCEDURE copy_a( p_month IN VARCHAR2, p_year IN NUMBER )
    AS
    BEGIN
      INSERT INTO a_history( month, year, copy_date, study, country, state )
        SELECT p_month, p_year, sysdate, study, country, state
          FROM a;
    END;
    

    You could also use dynamic SQL to avoid having to create 22 separate stored procedures. If the history tables always have the month, year, and copy_date as their first three columns and have the remaining columns in exactly the same order as the base table

    CREATE OR REPLACE PROCEDURE copy_table( p_table_name IN VARCHAR2, 
                                            p_month IN VARCHAR2, 
                                            p_year IN NUMBER )
    AS
      l_sql_stmt VARCHAR2(10000);
    BEGIN
      l_sql_stmt := 'INSERT INTO ' || p_table_name || '_hist ' ||
                    ' SELECT :mnth, :yr, sysdate, a.* ' ||
                    '   FROM ' || p_table_name;
      EXECUTE IMMEDIATE l_sql_stmt 
        USING p_month, p_year;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some Materialized views in our Oracle 9i database that were created a
I have created a table on an Oracle 10g database with this structure :
I have created a user with name ABC in Oracle database. Prior to this
I have an Oracle database backup file (.dmp) that was created with expdp .
I have a batch file that was created for an Oracle database that I'm
I have to use oracle database in android. I have tried to work as
We have an Oracle database here that's been around for about 10 years. It's
I have an oracle database populated with million records. I am trying to write
I have 3 Oracle database instances with the same data and scheme that I
I have an Oracle database that I am connecting to with PHP OCI8. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.