使用 INSERT 语句添加一个或多个记录到表中。

    示例如下:

    假设有如下数据的表 t1

    1. obclient> CREATE TABLE t1(c1 int primary key, c2 int);
    2. Query OK, 0 rows affected (0.16 sec)
    3. obclient> SELECT * FROM t1;
    4. Empty set (0.02 sec)
    • 单表插入:向表 t1 中插入一行数据

      1. obclient> INSERT INTO t1 VALUES(1,1);
      2. Query OK, 1 row affected (0.01 sec)
      3. obclient> SELECT * FROM t1;
      4. +----+------+
      5. | c1 | c2 |
      6. +----+------+
      7. | 1 | 1 |
      8. +----+------+
      9. 1 row in set (0.04 sec)
    • 单表插入:直接向子查询中插入数据

      1. obclient> INSERT INTO (SELECT * FROM t1) VALUES(1,1);
      2. Query OK, 1 row affected (0.01 sec)
      3. obclient> SELECT * FROM t1;
      4. +----+------+
      5. | C1 | C2 |
      6. +----+------+
      7. | 1 | 1 |
      8. +----+------+
      9. 1 row in set (0.01 sec)
    • 单表插入:包含 RETURNING 子句

      1. obclient> INSERT INTO t1 VALUES(1,1) RETURNING c1;
      2. +----+
      3. | C1 |
      4. +----+
      5. | 1 |
      6. +----+
      7. 1 row in set (0.02 sec)
      8. obclient> SELECT * FROM t1;
      9. +----+------+
      10. | C1 | C2 |
      11. +----+------+
      12. | 1 | 1 |
      13. +----+------+
      14. 1 row in set (0.01 sec)

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