Welcome to the Oracle community forum and interact with 2 million technical staff. Sometimes we need to update a table. When a record does not exist, we need to insert the table and update the record when it exists. We usually use if (exists (select...) update... elseinsert to scan the table twice, which is very inefficient.
Welcome to the Oracle community forum and interact with 2 million technical staff> we sometimes need to update a table and insert a record if it does not exist, update records when they exist. We usually use if (exists (select...) update... else insert to perform two-time table scan, which is very inefficient.
Welcome to the Oracle community forum and interact with 2 million technical staff> enter
We sometimes need to update a table. When a record does not exist, we need to insert the table and update the record if it exists. Normally we use if (exists (select ....) update .... else insert, which performs two-time table scanning with low efficiency. If there is a keyword merge above Oracle 9i, we can use it. Merge into requires two tag operations. We use dual
Merge into referer_stat L using (select '1' from dual) N on (L. webid = 234) when matched then update set count = count + 1 when not matched then insert (webid) values (234 );
When the referer_stat table contains the id = 234 record, the record is updated. If the referer_stat table does not exist, the record is inserted.