How do I MERGE and then UNMERGE data

Posted on 2008-06-19
Medium Priority
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 1000 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 1000 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: 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.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

752 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