I want to make a backup of table a1_crm_query
using EXCHANGE PARTITION
. This table contains rows with different statuses like 'ERROR', 'NEW', or 'DONE', and it would be great if there will be another table (a1_crm_query_LOG
) with statuses 'ERROR' and 'DONE' but my first table(a1_crm_query
) will be with only 'NEW'.
First of all I create my table:
CREATE TABLE ma_user.a1_crm_query (
ID NUMBER PRIMARY KEY,
DATA VARCHAR2(200)
);
Then I create second table with partition.
CREATE TABLE ma_user.a1_crm_query_LOG (
ID NUMBER PRIMARY KEY,
DATA VARCHAR2(200)
)
PARTITION BY LIST (DATA) (
PARTITION DONE_STATUS VALUES ('DONE'),
PARTITION ERROR_STATUS VALUES ('ERROR')
) ;
then insert values into a1_crm_query
:
INSERT INTO ma_user.a1_crm_query SELECT 1 , CAST('NEW' AS VARCHAR2(200)) FROM dual;
INSERT INTO ma_user.a1_crm_query SELECT 2 , CAST('DONE' AS VARCHAR2(200)) FROM dual;
INSERT INTO ma_user.a1_crm_query SELECT 3, CAST('ERROR' AS VARCHAR2(200)) FROM dual;
Now I want to create daily process which should move all rows with 'DONE' and 'ERROR' into table a1_crm_query_LOG
, a1_crm_query
should be only with 'NEW'.
I try to use exchange partition
:
ALTER TABLE ma_user.a1_crm_query_LOG EXCHANGE PARTITION ERROR_STATUS WITH TABLE ma_user.a1_crm_query WITHOUT VALIDATION;
ALTER TABLE ma_user.a1_crm_query_LOG EXCHANGE PARTITION DONE_STATUS WITH TABLE ma_user.a1_crm_query WITHOUT VALIDATION;
But after this ERROR_STATUS
partition contains all rows with all statuses.