【问题标题】:How to insert data into Oracle by using where not exists?如何使用 where not exists 向 Oracle 中插入数据?
【发布时间】:2019-03-28 18:24:32
【问题描述】:

当我使用此代码时,它返回错误“SQL 命令未正确结束” - 我错过了什么?

cmd.CommandText = "insert into trf_urun_bırım_detay " + 
    "values ('838', '1198385027', '950', '034') " +
    "where not exists(select * from trf_urun_bırım_detay where transfer_no = '838')";

【问题讨论】:

    标签: c# sql oracle


    【解决方案1】:

    您的 SQL 语句不正确。您要么必须使用 MERGE 语句,要么将 sql 语句更改为以下内容:

    insert into trf_urun_bırım_detay (transfer_no , Field2, Field3, Field4) 
    select '838','1198385027','950','034'
    from dual where not exists(select * from trf_urun_bırım_detay where transfer_no = '838');
    

    我在您的字段中使用了Field2,Field3,Field4,因为您没有提到他们的名字。

    【讨论】:

      猜你喜欢
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 2018-01-08
      • 2020-06-22
      • 1970-01-01
      相关资源
      最近更新 更多