使用 UPDATE 语句修改表中的字段值。

    示例如下:

    1. 创建示例表 t1

      1. obclient> CREATE TABLE t1(c1 int primary key, c2 int);
      2. Query OK, 0 rows affected (0.16 sec)
      3. obclient> INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(4,4);
      4. Query OK, 4 rows affected (0.01 sec)
      5. obclient> SELECT * FROM t1;
      6. +----+------+
      7. | c1 | c2 |
      8. +----+------+
      9. | 1 | 1 |
      10. | 2 | 2 |
      11. | 3 | 3 |
      12. | 4 | 4 |
      13. +----+------+
      14. 4 rows in set (0.06 sec)
    2. 单表更新:将表 t1t1.c1=1 对应的那一行数据的 c2 列值修改为 100

      1. obclient> UPDATE t1 SET t1.c2 = 100 WHERE t1.c1 = 1;
      2. Query OK, 1 row affected (0.02 sec)
      3. Rows matched: 1 Changed: 1 Warnings: 0
      4. obclient> SELECT * FROM t1;
      5. +----+------+
      6. | c1 | c2 |
      7. +----+------+
      8. | 1 | 100 |
      9. | 2 | 2 |
      10. | 3 | 3 |
      11. | 4 | 4 |
      12. +----+------+
      13. 4 rows in set (0.01 sec)
    3. 单表更新:直接操作子查询,将子查询中 v.c1=1 对应的那一行数据的 c2 列值修改为 100

      1. obclient> update (SELECT * FROM t1)v SET v.c2 = 100 WHERE v.c1 = 1;
      2. Query OK, 1 row affected (0.02 sec)
      3. Rows matched: 1 Changed: 1 Warnings: 0
      4. obclient> SELECT * FROM t1;
      5. +----+------+
      6. | C1 | C2 |
      7. +----+------+
      8. | 1 | 100 |
      9. | 2 | 2 |
      10. | 3 | 3 |
      11. | 4 | 4 |
      12. +----+------+
      13. 4 rows in set (0.01 sec)

    更多 UPDATE 语句相关的语法请参见《SQL 参考(Oracle 模式)》中 UPDATE 章节。