0

I have a table that I need to update each day. The data comes in a text file every time. I wrote a program that extracts the data from the text file and and writes it in the table, but now I want to modify it to just update the existing data. The data is mostly the same, it might differ only a few things.

I was thinking about MERGE but I don't know very well how I could use this in my program. All the examples that I saw used a second table.

So it would be like creating a second table in which I extract the current data, after which I make the merge into the old table to update the records. I want to avoid creating a second table, so I was wondering if there is any way to do this?

Thanks!

dres
  • 499
  • 6
  • 18
  • Here http://stackoverflow.com/questions/25451727/oracle-merge-only-not-matched-is-triggered you can find something interesting. Use MERGE only if you want an INSERT/UPDATE. Notice that MERGE is not atomic. – ROMANIA_engineer Sep 22 '14 at 12:06
  • Seems like a typical use case for `MERGE` - where's your problem? – Frank Schmitt Sep 22 '14 at 12:06
  • How are you extracting the data from the file? Are you using `EXTERNAL TABLE`? If yes, then simply use UPDATE statement to update only those records which are new. Or, even better is `MERGE` so that you can `INSERT WHEN NOT MATCHED` and `UPDATE WHEN MATCHED`. – Lalit Kumar B Sep 22 '14 at 12:07
  • 1
    @curiosu Care to elaborate? How is `MERGE` not atomic? – Frank Schmitt Sep 22 '14 at 12:08
  • 1
    I mean, if you want to INSERT if there is not line or UPDATE if there is a line ... you can have problems in a multithreading environment. If the first MERGE(INSERT) was done, the second MERGE can fail. (both see no row, but after the first one there is a row) – ROMANIA_engineer Sep 22 '14 at 12:16
  • This is tagged both Oracle and MySQL. Which of the two databases are you using? The syntax for `MERGE` and the set of valid options will often differ between databases. – Justin Cave Sep 22 '14 at 16:56

0 Answers0