Oracle SQL - 如何插入多行

时间:2017-09-28 22:06:26

标签: sql oracle insert

插入表格(col_identifier,句点)值('Proceeds',2016)

我想在2016年到2080年期间插入。是否可以在一行声明中插入此范围,或者我是否必须在每个期间写出来?

1 个答案:

答案 0 :(得分:3)

INSERT INTO ... SELECT与生成行的查询一起使用:

INSERT INTO table_name ( col_identifier, period )
  SELECT 'Proceeds', 2015 + LEVEL
  FROM   DUAL
  CONNECT BY 2015 + LEVEL <= 2080;

INSERT INTO table_name ( col_identifier, period )
  WITH years ( year ) AS (
    SELECT 2016 FROM DUAL
  UNION ALL
    SELECT year + 1 FROM years WHERE year < 2080
  )
  SELECT 'Proceeds', year
  FROM   years;