Hi,
I need to create a table by selecting data from another table based on one of its columns (which is a date field named t_data_date)...
1) Create a new archive table (t_arc) which stores 6 months of latest data from table (t_data) ... t_data currently has over 80 million rows and has about 18 months of data ...
2) Recreate t_data so that it stores only 3 months of latest data ...
At the end of this, I should have two tables (t_data with 3 months of latest data and t_arc with 6 months of latest data)
I need a generic solution to this, coz this needs to be done once every 3 months ...
This is solution we right now have is :
1) create table t_arc as
select /*+ parallel 16 */ * from t_data
where substr(t_data_date,4,3) in
(select substr(sysdate,4,3) from dual
union
select substr(add_months(sysdate,-1),4,3) from dual
union
select substr(add_months(sysdate,-2),4,3) from dual
union
select substr(add_months(sysdate,-3),4,3) from dual
union
select substr(add_months(sysdate,-4),4,3) from dual
union
select substr(add_months(sysdate,-5),4,3) from dual)
/
<This creates t_arc with 6 months of latest data>
2) rename t_data to t_data_old;
3) create table t_data as
select /*+ parallel 16 */ * from t_arc
where substr(t_data_date,4,3) in
(select substr(sysdate,4,3) from dual
union
select substr(add_months(sysdate,-1),4,3) from dual
union
select substr(add_months(sysdate,-2),4,3) from dual)
/
4) Fix the index(s) ...
5) Drop table t_data_old;
<This re-creates t_data >
Is this a good approach ? I am sure someone will have a suggestion to speed up the entire process ...
Thanx
-Maria
I need to create a table by selecting data from another table based on one of its columns (which is a date field named t_data_date)...
1) Create a new archive table (t_arc) which stores 6 months of latest data from table (t_data) ... t_data currently has over 80 million rows and has about 18 months of data ...
2) Recreate t_data so that it stores only 3 months of latest data ...
At the end of this, I should have two tables (t_data with 3 months of latest data and t_arc with 6 months of latest data)
I need a generic solution to this, coz this needs to be done once every 3 months ...
This is solution we right now have is :
1) create table t_arc as
select /*+ parallel 16 */ * from t_data
where substr(t_data_date,4,3) in
(select substr(sysdate,4,3) from dual
union
select substr(add_months(sysdate,-1),4,3) from dual
union
select substr(add_months(sysdate,-2),4,3) from dual
union
select substr(add_months(sysdate,-3),4,3) from dual
union
select substr(add_months(sysdate,-4),4,3) from dual
union
select substr(add_months(sysdate,-5),4,3) from dual)
/
<This creates t_arc with 6 months of latest data>
2) rename t_data to t_data_old;
3) create table t_data as
select /*+ parallel 16 */ * from t_arc
where substr(t_data_date,4,3) in
(select substr(sysdate,4,3) from dual
union
select substr(add_months(sysdate,-1),4,3) from dual
union
select substr(add_months(sysdate,-2),4,3) from dual)
/
4) Fix the index(s) ...
5) Drop table t_data_old;
<This re-creates t_data >
Is this a good approach ? I am sure someone will have a suggestion to speed up the entire process ...
Thanx
-Maria