【问题标题】:Auto-insert a range into an Oracle table将范围自动插入到 Oracle 表中
【发布时间】:2010-09-16 15:18:10
【问题描述】:

如何在给定增量范围的表中插入多行,其中行的一列包含值?

【问题讨论】:

    标签: sql oracle insert


    【解决方案1】:
      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

    【讨论】:

    • 插入多列时,您给出的 1,2,3..99 示例如何工作?例如。 1,sysdate 2,sysdate 另外,如果使用序列,那么对于一个范围,比如说 10k 值,我需要执行 10k 插入命令,对吧?
    • 我查看了“INSERT INTO SELECT”并得到了多列命令的答案:
    • INSERT INTO T2(ind,command) SELECT 1 + (Level -1) * 1,'do this' from dual connect by Level
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    相关资源
    最近更新 更多