merge into 用法

来源:互联网 发布:对美工电商有什么了解 编辑:程序博客网 时间:2024/05/17 08:42

使用例子

merge into user_role ausing (    select t1.*,t2.belongorg,to_char(sysdate, 'yyyy/mm/dd hh24:mm:ss') as curtime,'taj' as curuser    from (select t1.roleid,'add' as operation,'test1' as userid from awe_role_info t1 where t1.roleid in('3107','3109','3450')        union all        select t1.roleid,'del' as operation,'test1' as userid from awe_role_info t1 where t1.roleid in('3110','3111','3201','3400')    ) t1 join user_info t2 on t2.userid=t1.userid) b on (a.userid=b.userid and a.roleid=b.roleid)when matched then    update set a.grantor=a.grantor where b.operation = 'del'    delete where b.operation = 'del'when not matched then    insert(userid,roleid,grantor,begintime,status,inputuser,inputorg,inputtime)    values(b.userid,b.roleid,b.curuser,b.curtime,'1',b.curuser,b.belongorg,b.curtime)    where b.operation = 'add';
0 0