# Oracle merge into更新表

merge into的形式:


MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] and [...]...)
WHEN MATCHED THEN
    [UPDATE sql]
WHEN NOT MATCHED THEN

    [INSERT sql]

用merge into 可以根据表b来更新表a或者新增

merge into bank b using (select id,fse,grzh,kh from transaction) tran on(tran.grzh=b.grzh)

--根据表b的数据,表b与表a字段关联,如能关联上,就更新表a否则新增

when matched then

    update bank set fse = grzh.fse  where grzh=tran.grzh

when not matched then

    insert (b.fse,b.grzh,b.kh) values (tran.fse,tran.grzh,tran.kh)

 

 

你可能感兴趣的:(merge,into)