on duplicate key oracle,INSERT … ON DUPLICATE KEY UPDATE

on duplicate key oracle,INSERT … ON DUPLICATE KEY UPDATEINSERT…ONDUPLICATEKEYUPDATEIfyouspecifyONDUPLICATEKEYUPDATE,andarowisinsertedthatwouldcauseaduplicatevalueinaUNIQUEindexorPRIMARYKEY,MySQLperformsanUPDATEoftheold…

on duplicate key oracle,INSERT ... ON DUPLICATE KEY UPDATE

INSERT … ON DUPLICATE KEY UPDATE

If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, MySQL performs an UPDATE of the old row. For example, if column a is declared as UNIQUE and contains the value 1, the following two statements have similar effect:

INSERT INTO table (a,b,c) VALUES (1,2,3)

ON DUPLICATE KEY UPDATE c=c+1;

UPDATE table SET c=c+1 WHERE a=1;

(The effects are not identical for an InnoDB table where a is an auto-increment column. With an auto-increment column, an INSERT statement increases the auto-increment value but UPDATE does not.)

The ON DUPLICATE KEY UPDATE clause can contain multiple column assignments, separated by commas. for example ,

INSERT INTO t_vehicle

(vehicle_id,

model_id,

vehicle_no,

frame_no,

engine_no

)

VALUES

(1, 2522, ‘456’, ‘789’, ‘012’) ON DUPLICATE KEY UPDATE

vehicle_id = 1 , frame_no = ‘123’ , vehicle_no = ‘323’;

如果行作为新记录被插入,则受影响行的值为1;如果原有的记录被更新,则受影响行的值为2。

今天的文章on duplicate key oracle,INSERT … ON DUPLICATE KEY UPDATE分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/33126.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注