该语句用于添加一个或多个记录到表。
格式
INSERT [INTO] tblname
[(colname,...)]
{VALUES|VALUE} ({expr | DEFAULT},...)
[ ON DUPLICATE KEY UPDATE
colname=expr
[, colname=expr] ... ] ;
或者
INSERT [INTO] tblname
[(colname,...)]
{VALUES|VALUE} (colvalues,...)
[ON DUPLICATE KEY UPDATE
colname=expr
[, colname=expr] ... ] ;
Oceanbase>show create table test;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
UNIQUE KEY `a_uniq` (`a`) BLOCK_SIZE 16384
) DEFAULT CHARSET = utf8mb4 REPLICA_NUM = 3 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
Oceanbase>insert into test values(1,2);
Query OK, 1 row affected (0.01 sec)
Oceanbase>insert into test values(1,3);
ERROR 1062 (23000): Duplicate entry '1' for key 'a_uniq'
Oceanbase>insert into test values(1,3) on duplicate key update a = a+1;
Query OK, 2 rows affected (0.01 sec)
Oceanbase>select * from test;
+------+------+
| a | b |
+------+------+
| 2 | 2 |
+------+------+
1 row in set (0.01 sec)
Oceanbase>show create table tp;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tp | CREATE TABLE `tp` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 REPLICA_NUM = 3 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE partition by hash(a) partitions 7 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
Oceanbase>insert into tp values(1,2),(2,3),(3,4);
ERROR 1235 (0A000): Insert data cross partition not supported
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。