Oracle merge statement

Source: Internet
Author: User


Oracle merge statement merge into table name a using (select? As field 1 ,? As field 2 ,..... from dual) B on (. field 1 = B. field 1 and ....) (Judgment condition) when matched then update set field 1 = Field 1 ,...... when not matched then insert (Field 1, Field 2 ,...) values (B. field 1, B. field 2 ,....) example of www.2cto.com: Table Name: TR_RUNNING_MONITOR; field name: LAST_TASK_ROWID, LAST_CRAWL_DATE,
START_TIME, DOC_COUNT, HIT_COUNT, OP_TYPE, DOC_TYPE merge into TR_RUNNING_MONITOR a using (select? As LAST_TASK_ROWID ,? As LAST_CRAWL_DATE ,? As START_TIME ,? As DOC_COUNT,
? As HIT_COUNT ,? As OP_TYPE ,? As DOC_TYPE, sysdate as UPDATE_TIME from dual) B on (. OP_TYPE = B. OP_TYPE and. DOC_TYPE = B. DOC_TYPE) when matched then update set DOC_COUNT = DOC_COUNT, HIT_COUNT = HIT_COUNT, START_TIME = START_TIME, UPDATE_TIME
= UPDATE_TIME, LAST_CRAWL_DATE = LAST_CRAWL_DATE, expires = LAST_TASK_ROWID when not matched then insert (OP_TYPE, DOC_TYPE, DOC_COUNT, HIT_COUNT, START_TIME, UPDATE_TIME, LAST_CRAWL_DATE,
LAST_TASK_ROWID) values (B. OP_TYPE, B. DOC_TYPE, B. DOC_COUNT, B. HIT_COUNT, B. START_TIME, B. UPDATE_TIME,
B. LAST_CRAWL_DATE, B. LAST_TASK_ROWID)
Note: Use OP_TYPE and DOC_TYPE to compare the two fields in the table TR_RUNNING_MONITOR and perform the update at the same time,
Insert simultaneously
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.