English 中文(简体)
将Oracle合并查询转换为MySQL查询
原标题:
  • 时间:2008-12-26 10:45:53
  •  标签:
    MERGE INTO PAGEEDITCONTROL A
      USING (SELECT
               1585  AS PAGEID
       , admin  AS EDITUSER
       ,sysdate AS EDITDATE
          FROM DUAL) B
      ON (A.PAGEID = B.PAGEID)
      WHEN MATCHED THEN
      UPDATE SET
      A.EDITUSER = B.EDITUSER
     ,A.EDITDATE = B.EDITDATE
      WHEN NOT MATCHED THEN
   INSERT  (
      A.PAGEID
     ,A.EDITUSER
     ,A.EDITDATE
      )VALUES(
      B.PAGEID
     ,B.EDITUSER
     ,B.EDITDATE
      )
问题回答
INSERT INTO  
pageeditcontrol (pageid, edituser, editdate) 
VALUES  ( 1585 ,  admin , sysdate()) 
ON DUPLICATE KEY UPDATE 
edituser = values(edituser), 
editdate = values(editdate);

MySQL 有一个类似的结构,看起来不像更新插入,而更像插入: INSERT ... ON DUPLICATE KEY UPDATE(请参阅 MySQL 参考手册)。





相关问题
热门标签