自动将范围插入Oracle表

时间:2010-09-16 15:18:10

标签: sql oracle insert

如果给定增量范围,如何在表中插入一些行,并且该行的一列包含值?

1 个答案:

答案 0 :(得分:7)

  INSERT INTO YourTable(YourColumn)
  SELECT 1 + (Level -1) * YourIncrement from dual connect by Level < TotalNumbers)

  i.e.


  INSERT INTO YourTable(YourColumn)
  SELECT 1 + (Level -1) * 1 from dual connect by Level < 100)

创建序列1,2,3 ... 99

  INSERT INTO YourTable(YourColumn)
  SELECT 1 + (Level -1) * 2 from dual connect by Level < 100)

创建序列1,3,5 .. 100

或者您可以使用SEQUENCES