首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

Oracle SQL 查寻,删除重复行,有则更新,无则插入

2012-08-16 
Oracle SQL 查找,删除重复行,有则更新,无则插入MERGE INTO CRPROPTREND T1 USING DUAL T2ON (T1.URIMD5a

Oracle SQL 查找,删除重复行,有则更新,无则插入

    MERGE INTO CRPROPTREND T1 USING DUAL T2    ON (T1.URIMD5="abc")    WHEN MATCHED THEN    INSERT VALUES(...)    WHEN NOT MATCHED THEN    UPDATE SET ...;    



-- This query is not editable, but generally faster Select          URIMD5,         count(*)from     RUNPPV.CRPROPTRENDgroup by          URIMD5having   count(*) > 1-- This query is editable, but generally slower Select A1.*, A1.rowidfrom RUNPPV.CRPROPTREND A1 where exists (Select 'x' from RUNPPV.CRPROPTREND A2 where A1.URIMD5 = A2.URIMD5and A1.ROWID <> A2.ROWID)-- To delete all but one of each duplicate row, -- change the first line to 'Delete' -- and change the '<>' to '>' (keeps first duplicate) --                     or '<' (keeps last duplicate) 

热点排行