【问题标题】:Insert multiple rows from select into another table从选择中插入多行到另一个表中
【发布时间】:2015-06-26 11:43:04
【问题描述】:

假设我有 `table1(col1,col2,col3),在 col1 和 col3 上插入的值将相同,但在 col2 上插入的值来自选择查询的结果。

如何编写我的查询以便我可以一次执行多次插入? 查询应该做什么的示例:

col1  |  col2   | col3

 1        val1     0
 1        val2     0
 1        val3     0

【问题讨论】:

    标签: sql oracle oracle10g


    【解决方案1】:

    如果我理解正确,你会使用insert . . .select

    insert into table1(col1, col2, col3)
        select 1, col2, 0
        from <your other query here>;
    

    【讨论】:

    • 能否在此处的选择查询中添加 Where 子句,因为有时我们可能只想使用第二张表的某些行?
    • @DhumilAgarwal 。 . .是的,您可以在select 中添加where 子句。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 2018-07-27
    相关资源
    最近更新 更多