Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

How do I MERGE and then UNMERGE data

We have a app using oracle db, it stores a master patient file with linked tables containing clinical data . Sometime the patient is entered twice so the user requires a function to merge the two patient clinical data to one client record - no problem
However some time the merge is done incorrectly so they wish to unmerge the data.
Does anyone know a function within Oracle which would enbale the database to rollback the data for only these 2 patients to a point before the merge

Thanks in anticipation
0
kevincox29
Asked:
kevincox29
  • 2
  • 2
2 Solutions
 
dragos_craciunCommented:
Use the flashback feature of Oracle.
Configure undo retention to a reasonable amount of time and then write something like:

SELECT * from TABLEX t AS OF TIMESTAMP TO_TIMESTAMP('2008-06-19 12:00:00', 'YYYY-MM-DD HH24:MI:SS')

this will show you the data in the table as it was at that time (if that data is still in the flashback space)
0
 
MilleniumaireCommented:
It isn't so much a "function within Oracle" that you need other than a routine to perform the de-merging which applies the required business rules.

If you are looking for a one-off fix and it hasn't been too long (hours) since the data was merged then you could look at using the flashback facility to take a copy of the data prior to the merge and use this to perform the de-merge.  If it has been many hours or days since the merge occurred you will have to write code to perform the de-merge as I said above.

An example of a flashback query:

SELECT * from table_name
AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '50' minute)
0
 
kevincox29Author Commented:
Hi thanks for the answer.
With this query is this for all data to revert back, in my case I only want certain records to reert to their original state
0
 
MilleniumaireCommented:
This is a select statement and therefore it is NOT changing any data.

You can use the statement to retrieve the data as it was BEFORE the data was merged.  If you only want to retrieve some rows from the table then add a WHERE clause (just like any other query).

Once you have identified the rows as they were BEFORE the data was merged you will need to de-merge the data.  How you do this depends on how the data was merged in the first place.  It may involve the following:

delete the new merged row from the patient table  (if a new row was created for the merged data)
insert the two old de-merged rows (retrieved by the flashback query) into the current patient table.

Alternativeyl, it may be simply a process of using the data retrieved from the flashback query to update the current records in the patient table.

I would suggest you use the flashback query to create a copy of the old table so that you can then use this copy table to update your current patient table.

CREATE TABLE OLD_table_name AS
SELECT * from table_name
AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '50' minute)

Flashback queries aren't generally used as a means of coding business functionality.  That is, if your users/IT department requires a procedure by which they regularly need to de-merge data then I would suggest that using flashback queries isn't the way to go.  In this case you need to change your application design and build this new functionality.

If this is a one-off fix then by all means use the flashback query to help you, but I suspect by now the data will be too old to retrieve, unless your dba has set a long retention period.
0
 
kevincox29Author Commented:
So in conclusion we will need to write this into our application

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now