Oacle 插入多条记录的语法理解;INSERT ALL INTO ....... SELECT 1 FROM dual;

单表Insert into的语句就不说了,这里主要说插入多条语句的说明

For a multitable insert operation, each expression in the values_clause must refer to columns returned by the select list of the subquery. If you omit the values_clause, then the select list of the subquery determines the values to be inserted, so it must have the same number of columns as the column list of the corresponding insert_into_clause. If you do not specify a column list in the insert_into_clause, then the computed row must provide values for all columns in the target table.

对于多表插入操作,values_clause 中的每个表达式都必须引用子查询的选择列表返回的列。如果省略values_clause,则子查询的select 列表决定了要插入的值,因此它的列数必须与相应insert_into_clause 的列列表相同。如果未在 insert_into_clause 中指定列列表,则计算行必须为目标表中的所有列提供值。


For both types of insert operations, if you specify a column list in the insert_into_clause, then the database assigns to each column in the list a corresponding value from the values clause or the subquery. You can specify DEFAULT for any value in the values_clause. If you have specified a default value for the corresponding column of the table or view, then that value is inserted. If no default value for the corresponding column has been specified, then the database inserts null. Refer to "About SQL Expressions" and SELECT for syntax of valid expressions.


对于这两种类型的插入操作,如果您在 insert_into_clause 中指定了一个列列表,那么数据库会从 values 子句或子查询中为列表中的每一列分配一个相应的值。您可以为 values_clause 中的任何值指定 DEFAULT。如果您为表或视图的相应列指定了默认值,则会插入该值。如果未指定相应列的默认值,则数据库插入空值。有关有效表达式的语法,请参阅“关于 SQL 表达式”和 SELECT。

格式语法: INSERT ALL INTO tab_name(col_name) VALUES(val...) SELECT 1 FROM dual;

  • 如果省略values_clause子句,那么INSERT INTO的表的值来自SELECT子句查询的列值,需要SELECT为每个声明的列定义都返回值;也就是可以提供后退默认值
  • 如果省略col_defines列定义,那么提供的VALUES子句或者SELECT子查询都需要为每个列赋予值进行插入
  • 如果VALUES子句中使用DEFAULT关键字,那么值来源于列的默认值,如果列没有默认值,那么会插入NULL。

注意:

  1. values_clause 子句中可以使用SELECT子查询的列的值
  2. 如果需要使用SELECT子查询,切记需要与 {声明的列 或者 与表中列(没有声明列名)} 都需要赋予默认值

官方文档里来源地址:https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_9014.htm#i2121694 搜索 values_clause 可快速定位相关的位置

复制请注明出处,在世界中挣扎的灰太狼
原文地址:https://www.cnblogs.com/XingXiaoMeng/p/15438757.html