该语句用于修改表中的字段值。
UPDATE [IGNORE] table_references
SET update_asgn_list
[WHERE where_condition]
[ORDER BY order_list]
[LIMIT row_count];
table_references:
tbl_name [PARTITION (partition_name,...)] [, ...]
update_asgn_list:
column_name = expr [, ...]
order_list:
column_name [ASC|DESC] [, column_name [ASC|DESC]…]
参数 |
描述 |
---|---|
IGNORE |
在 INSERT 语句执行过程中发生的错误将会被忽略。 |
table_references |
指定修改表名,多表修改时,表名直接‘,’作为间隔。 |
where_condition |
指定过滤条件。 |
row_count |
限制的行数。 |
tbl_name |
插入表名。 |
partition_name |
插入表指定的分区名。 |
column_name |
列名。 |
column_name ASC |
按列名升序修改。 |
column_name DESC |
按列名降序修改。 |
不管是多表还是单表更新都不支持直接对子查询进行更新值操作,例如:update (select * from t1) set c1 = 100;
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)
OceanBase(admin@test)>update t1 set t1.c2 = 100 where t1.c1 = 1;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
OceanBase(admin@test)>select * from t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 100 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
+----+------+
4 rows in set (0.01 sec)
OceanBase(admin@test)>update t1 set t1.c2 = 100 order by c2 limit 2;
Query OK, 2 rows affected (0.02 sec)
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)
OceanBase(admin@test)>update t2 partition(p2) set t2.c2 = 100 where t2.c1 > 2;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
OceanBase(admin@test)>select * from t2;
+----+------+
| c1 | c2 |
+----+------+
| 5 | 5 |
| 1 | 1 |
| 2 | 2 |
| 3 | 100 |
+----+------+
4 rows in set (0.06 sec)
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 |
+----+------+
4 rows in set (0.00 sec)
OceanBase(admin@test)>select * from t2;
+----+------+
| c1 | c2 |
+----+------+
| 5 | 5 |
| 1 | 200 |
| 2 | 200 |
| 3 | 200 |
+----+------+
4 rows in set (0.01 sec)
OceanBase(admin@test)>update t1,t2 partition(p2) set t1.c2 = 100, t2.c2 = 200 where t1.c2 = t2.c2;
Query OK, 6 rows affected (0.02 sec)
Rows matched: 6 Changed: 6 Warnings: 0
OceanBase(admin@test)>select * from t1;
+----+------+
| c1 | c2 |
+----+------+
| 1 | 100 |
| 2 | 100 |
| 3 | 100 |
| 4 | 4 |
+----+------+
4 rows in set (0.01 sec)
OceanBase(admin@test)>select * from t2;
+----+------+
| c1 | c2 |
+----+------+
| 5 | 5 |
| 1 | 200 |
| 2 | 200 |
| 3 | 200 |
+----+------+
4 rows in set (0.01 sec)
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 |
+----+------+
4 rows in set (0.01 sec)
NUMBER是变长、精确的数值类型,占 4~40 字节存储空间,其中 4 字节存放NUMBER的元数据信息, 36 字节存放NUMBER的...
将字符串值转换为日期值时,会有下列转换规则:如果指定了数值格式化元素的所有数值(包括前导零点),则可以从日期字符串中省略...
条件判断表达式中的空值指的是条件= NULL、!= NULL、NULL =、NULL !=中的NULL,作逻辑判断使用,判断结果...
以下是一些有效的 Schema 对象命名示例:last_namehorsehr.hire_date"EVEN THISTHAT!"a_very_long_and_valid_name这些示例都遵循...
本章将讨论如何在 SQL 语句的上下文中引用 Schema 对象。本章包括:引用 Schema 对象引用分区表和索引引用对象类型属性和方法...