How do I MERGE and then UNMERGE data

Posted on 2008-06-19
Last Modified: 2013-12-19
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
Question by:kevincox29
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

dragos_craciun earned 250 total points
ID: 21823501
Use the flashback feature of Oracle.
Configure undo retention to a reasonable amount of time and then write something like:


this will show you the data in the table as it was at that time (if that data is still in the flashback space)
LVL 16

Assisted Solution

Milleniumaire earned 250 total points
ID: 21823526
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

Author Comment

ID: 21829294
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
LVL 16

Expert Comment

ID: 21829328
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.

SELECT * from table_name

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.

Author Comment

ID: 21829535
So in conclusion we will need to write this into our application


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Character matching different date formats for dates between 6 80
Database Design Dilemma 6 71
plsql job on oracle 18 107
populate value based on what is selected in lov 2 66
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to recover a database from a user managed backup

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question