Use these scripts with Oracle Database to archive or purge the interaction history tables on Windows OS. The scripts allow you to move the FACT table records, merge the Dimension records, and delete the records from the FACT table. Before you use any of the scripts, back up the source and target interaction history tables and create indexes on the columns. Indexes improve performance when you read data from the archived tables.
Note: The IH scripts contain variables like <source_user_name>, <target_user_name> which you need to provide before executing any of the sample scripts below.
Before you perform this task, make sure you have full access to the source and the destination databases (you need the database admin privileges).
Move data.
If a table does not exist, execute the following script:
COPY FROM <source_user_name>/<source_pwd>@<source_tnsname> TO <target_user_name>/<target_pwd>@<target_tnsname> CREATE PR_DATA_IH_FACT USING SELECT * FROM PR_DATA_IH_FACT;
If a table exists with the exact same columns:
Execute the following script:
COPY FROM <source_user_name>/<source_pwd>@<source_tnsname> TO <target_user_name>/<target_pwd>@<target_tnsname> INSERT PR_DATA_IH_FACT USING SELECT * FROM PR_DATA_IH_FACT;
Before you perform this task, make sure that all the dimension tables are created and have index on the PZID column.
Connect to the target database.
Copy the table from the source database to a temporary table in the destination database.
COPY FROM <source_user_name>/<source_pwd>@<source_tnsname> TO <target_user_name>/<target_pwd>@<target_tnsname> CREATE PR_DATA_IH_DIM_<DIMENSION_NAME>_STAGE USING SELECT * FROM PR_DATA_IH_DIM_<DIMENSION_NAME>;
Merge the records from the temporary table to the actual dimension table.
MERGE INTO PR_DATA_IH_DIM_<DIMENSION_NAME> T USING PR_DATA_IH_DIM_<DIMENSION_NAME>_STAGE S ON (S.PZID = T.PZID) WHEN NOT MATCHED THEN INSERT (T.column1 [, T.column2 ...]) VALUES (S.column1 [, S.column2 ...]);
Commit changes.
COMMIT;
Delete the temporary table.
DROP TABLE PR_DATA_IH_DIM_<DIMENSION_NAME>_STAGE;
If you want to merge the dimension records from the source database to the target database, repeat this procedure for all the dimension tables.
Connect to the source database.
Execute the following script:
DELETE FROM PR_DATA_IH_FACT WHERE PXOUTCOMETIME < TO_DATE(<DATE_STRING>, <DATE_FORMAT_STRING>);
Example:
DELETE FROM PR_DATA_IH_FACT WHERE PXOUTCOMETIME < TO_DATE('2015-01-07', 'YYYY-MM-DD')