In the development we often encounter such a scene, column, such as user modification simple personal basic information, this time need to determine whether the user's basic information exists, if the first entry does not exist in the table insert a message, if there is the Update table information.
To achieve this kind of scenario is very simple, our most commonly used is to query the user's basic information, execute the Select method, if the data exists on the implementation of the Update method, if it does not exist, execute the Insert method. This is a solution to the idea.
When it is simply a condition to judge, we also have another kind of database-level solution is merge into, many databases have this statement, because I use Oracle, here to record the use of Oracle, from version 9 to support the syntax.
MERGEINTO table_name t1USING (Select A, b b,c C from dual) T2On (t1
. A = t2.a)when matched then UPDATE T1 SET b= B, c= C is not matched then INSERT t1
values (a,b,c);
Oracle database, overwriting insert data----Merge into