七郎's JavaBlog

草木竹石皆可為劒。至人之用人若鏡,不將不迎,應而不藏,故能勝物而不傷。
posts - 60, comments - 14, trackbacks - 0, articles - 0

ORACLE插入失败后更新

Posted on 2007-06-14 11:57 七郎归来 阅读(221) 评论(0)  编辑  收藏

create table t1(cid int,cname varchar2(100));
insert into t1 values (1,'1');
create table t2(cid int,cname varchar2(100));
insert into t2 values(1,'3');       
insert into t2 values(2,'4'); 


MERGE INTO t1 a
      USING t2 b
    on (a.cid=b.cid)
    WHEN MATCHED  THEN
        UPDATE SET a.cname=b.cname
    WHEN NOT MATCHED THEN
        INSERT (a.cid,a.cname ) VALUES ( b.cid,b.cname );


只有注册用户登录后才能发表评论。


网站导航: