Want to insert a piece of data, to avoid repeated insertions, and do not want to toss two back to the database connection operation, you can refer to the following methods.
INSERT into Table (Column1,column2,column3 ... columnn) SELECT value1,value2,value3 ... valuen from Dual WHERE not EXISTS ( SELECT*from table WHERE = ?);
dual is a table that exists to build query statements that are common in Oracle, with the INSERT ... SELECT builds the table that we need and specifies the data item.
EXISTS Through this judgment whether the existence of the function, it is exempt from our if-else to do the cumbersome operation.
Cases:
INSERT intocontent (detail, status, BeginTime, EndTime) SELECT @detail, 1, NULL, NULL fromDUALWHERE not EXISTS( SELECTcontentId fromcontentWHEREDetail=@detail);
@detail is the content to be deposited, the content is retrieved, if you want to do so, it is best to do a unique constraint on the field, or indexed.
Dispense with the If-else, in the Ibatis configuration is OK, ha!
There is a more determined approach--replace into:
Replace into' taisau '. ' RecordInfo ' (' WorkID ', ' bartificialattendance ', ' fthreshold ', ' attendance_time ', ' Picpath ') Select '%s','1','60.00','%d-%02d-%02d%02d:%02d:%02d.000','%s' fromDualwhere not exists(SELECT' Attendance_time ' from' Taisau '. ' RecordInfo 'WHERE' WorkID '= '%s' and' Attendance_time '= '%d-%02d-%02d%02d:%02d:%02d.000');
MySQL statement level avoids repeated insertions--insert Select not Exist