Moving data older than 2 years in all fact tables to respective archive tables & purging data [message #651625] |
Sat, 21 May 2016 00:53 |
|
krisc2499
Messages: 4 Registered: May 2016 Location: Hyderabad
|
Junior Member |
|
|
Hi,
I have a requirement where i have to copy data older than 2 years from all fact tables to their respective archive table (one archive table for each fact table)
And then validate if data has been inserted into Archive table and delete data older than 2 years in main fact tables.
I don't have knowledge in pl/sql.
I need your advise on how to achieve this.
Thanks
Krishna
|
|
|
|
Re: Moving data older than 2 years in all fact tables to respective archive tables & purging data [message #651627 is a reply to message #651626] |
Sat, 21 May 2016 01:12 |
|
krisc2499
Messages: 4 Registered: May 2016 Location: Hyderabad
|
Junior Member |
|
|
Thanks for quick response.
So far , i have created a Control Table with structure as
CREATE TABLE "W_CONTROL_TABLE" ("TABLE_NAME" VARCHAR2(500 BYTE),"COL_USED_FOR_ARCH" VARCHAR2(500 BYTE),"PERIOD_IN_MONTHS" NUMBER(10,0),"ARCHIVED_TO_TABLE" VARCHAR2(500 BYTE))
I have to do this for many tables(around 750) and have to do this every week, so we have to write procedure to do this dynamically rather than doing for each table.
In above control table, we are storing Original Table name - TABLE_NAME , Column which acts as a filter in each table to get data older than specific period - COL_USED_FOR_ARCH ,
column to know for how older data should be purged - PERIOD_IN_MONTHS , column to know to what archive table should be used to copy data from original table -ARCHIVED_TO_TABLE.
I hope you got my full scenario.
So i guess i have to write a PL/SQL procedure with one or two cursors to do this dynamically.
But i am not able to implement this, since i am very new to pl/sql.
Thanks
|
|
|
|
Re: Moving data older than 2 years in all fact tables to respective archive tables & purging data [message #651637 is a reply to message #651627] |
Sat, 21 May 2016 08:15 |
|
EdStevens
Messages: 1376 Registered: September 2013
|
Senior Member |
|
|
krisc2499 wrote on Sat, 21 May 2016 01:12Thanks for quick response.
So far , i have created a Control Table with structure as
CREATE TABLE "W_CONTROL_TABLE" ("TABLE_NAME" VARCHAR2(500 BYTE),"COL_USED_FOR_ARCH" VARCHAR2(500 BYTE),"PERIOD_IN_MONTHS" NUMBER(10,0),"ARCHIVED_TO_TABLE" VARCHAR2(500 BYTE))
I have to do this for many tables(around 750) and have to do this every week,
First, for your own sanity you need to learn to format your code. And for the sanity of those from whom you seek assistance, you should learn to preserve that format by using the code tags when you post. Also, remove the double-quotes. They serve no purpose but to add clutter. Also putting everything in upper case also makes it harder to read. I haven't used all upper-case since I got off the IBM mainframe back in the '90s. Also, there is no need to explicitly define the varchars as BYTE, as that is the default. Again, just adds clutter to your code. Also, why define columns that are being used to store the names of oracle objects as varchar2(500) when then data being stored there can never exceed 30 bytes (the defined limit for table/column names)?
create table w_control_table
(table_name varchar2(30),
col_used_for_arch varchar2(30),
period_in_months number(10,0),
archived_to_table varchar2(30)
)
Now back your question -- are you really defining 750 new tables every week? Sounds to me like a very flawed approach to some unknown (to us) problem. Perhaps if you were to step back a bit. Explain the business problem, the reasoning behind this approach. I'll bet someone can find a much more elegant solution.
|
|
|
|
|
|
|
|
|