Home > Database > Mysql Tutorial > oracle merge语句

oracle merge语句

WBOY
Release: 2016-06-07 17:21:59
Original
1133 people have browsed it

用OP_TYPE和DOC_TYPE跟表TR_RUNNING_MONITOR中的这两个字段比较,相同时进行update,不同时进行insert

merge into 表名 a using

(select ? as 字段1,? as 字段2,..... from dual)

b on (a.字段1=b.字段1 and ....)(判断的条件)

when matched then

update set 字段1=字段1,......

when not matched then

insert (字段1,字段2,...) values(b.字段1,b.字段2,....)

例子如下:表名:TR_RUNNING_MONITOR ;字段名: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 (a.OP_TYPE=b.OP_TYPE and a.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,LAST_TASK_ROWID=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)


说明:用OP_TYPE和DOC_TYPE跟表TR_RUNNING_MONITOR中的这两个字段比较,,相同时进行update,不同时进行insert

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template