【问题标题】:Oracle SQL - Insert Statement with Where ClauseOracle SQL - 带有 Where 子句的插入语句
【发布时间】:2020-11-09 22:42:25
【问题描述】:

我正在尝试将数据插入到表中特定行的特定列中,我确信我做错了,因为这是我第一次使用 Where: 执行插入语句

insert INTO mekka_h_o_a_fees
  columns(money_handed_to_commity),
  Where Month_Year = July
  VALUES(Yes)

提前谢谢你

【问题讨论】:

    标签: sql oracle sql-update sql-insert where-clause


    【解决方案1】:

    我想你想要update,而不是insert。语法是:

    update mekka_h_o_a_fees
    set money_handed_to_commity = 'Yes'
    where month_year = 'July'
    

    这会将列money_handed_to_commity 设置为'Yes' 在列month_year 具有值'July' 的行上。

    【讨论】:

    • 没错,行已经存在我只需要更新一个空单元格
    • 如果我想更新多个月怎么办?我试过了,它没有用
    • update mekka_h_o_a_fees set money_handed_to_commity = 'Yes' where month_year = 'August''SEPT';
    • @AnouarSeljouki: where month_year in ('August', 'Sept')
    【解决方案2】:

    如果您想基于不同表中的另一行插入新行,则可以使用INSERT INTO ... SELECT ... WHERE ...(并且您需要在字符串文字值周围加上单引号):

    INSERT INTO mekka_h_o_a_fees (money_handed_to_commity)
    SELECT 'Yes'
    FROM   some_table
    WHERE  Month_Year = 'July';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      相关资源
      最近更新 更多