Domanda

I have a TempTable with new content, now i like to Insert/Update the MainTable with this. I need a fast way,but the table is realy big.

TempTable:

  • TIME |CUSTOMER| VALUE
  • TimeStamp String Float

Insert (TIME|CUSTOMER|VALUE) if not exists else updated VALUE

MainTable:

  • TIME |CUSTOMER| VALUE
  • TimeStamp String Float

I have found some SQL Query but these are to slow.

Have anyone a idea how i can do this with pl/sql?

È stato utile?

Soluzione

MERGE statement is that you need:

http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606

SQL> select * from t;

  ID N                                                                          
---- -                                                                          
   1 a                                                                          

SQL> select * from t1;

  ID NA                                                                         
---- --                                                                         
   1 a1                                                                         
   2 b1                                                                         

SQL> merge into t using t1 on (t.id = t1.id)
  2  when matched then
  3  update set t.name = t1.name
  4  when not matched then
  5  insert (t.id, t.name) values(t1.id, t1.name)
  6  /

2 rows merged.

SQL> select * from t;

  ID NA                                                                         
---- --                                                                         
   1 a1                                                                         
   2 b1     
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top