- 创建示例表 t1 和 t2。
OceanBase(admin@test)>create table t1(c1 int primary key, c2 int);
Query OK, 0 rows affected (0.16 sec)
OceanBase(admin@test)>select * from t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
+----+------+
4 rows in set (0.06 sec)
OceanBase(admin@test)>create table t2(c1 int primary key, c2 int) partition by key(c1) partitions 4;
Query OK, 0 rows affected (0.19 sec)
OceanBase(admin@test)>select * from t2;
+----+------+
| c1 | c2 |
+----+------+
| 5 | 5 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
+----+------+
4 rows in set (0.02 sec)
- 将表 t1 中按照 c2 列排序的前两行数据的 c2 列值修改为 100。
OceanBase(admin@test)>update t1 set t1.c2 = 100 order by c2 limit 2;
Rows matched: 2 Changed: 2 Warnings: 0
OceanBase(admin@test)>select * from t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 100 |
| 2 | 100 |
| 3 | 3 |
| 4 | 4 |
+----+------+
4 rows in set (0.01 sec)
- 将表 t2 中 p2 分区的数据中 “t2.c1 > 2” 的对应行数据的 c2 列值修改为 100。
- 修改多个表。将 t1 表和 t2 表中满足 “t1.c1 = t2.c1” 对应行的数据 t1 表中的 c2 列值修改为 100,t2 表中的 c2 列值修改为 200。
OceanBase(admin@test)>update t1,t2 set t1.c2 = 100, t2.c2 = 200 where t1.c2 = t2.c2;
Query OK, 6 rows affected (0.03 sec)
Rows matched: 6 Changed: 6 Warnings: 0
OceanBase(admin@test)>select * from t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 100 |
| 2 | 100 |
| 3 | 100 |
| 4 | 4 |
+----+------+
OceanBase(admin@test)>select * from t2;
+----+------+
| c1 | c2 |
+----+------+
| 5 | 5 |
| 1 | 200 |
| 2 | 200 |
| 3 | 200 |
+----+------+
4 rows in set (0.01 sec)
- 修改多个表。修改 t1 表和 t2 表的p2分区中满足 “t1.c1 = t2.c1” 对应行的数据 t1 表中的 c2 列值修改为 100,t2 表中的 c2 列值修改为 200。
- 对可更新视图 v 进行更新值。
OceanBase(admin@test)>create view v as select * from t1;
Query OK, 0 rows affected (0.07 sec)
OceanBase(admin@test)>update v set v.c2 = 100 where v.c1 = 1;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
OceanBase(admin@test)>select * from v;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 100 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
+----+------+