首页 > 解决方案 > 如何使用 where not exists 向 Oracle 中插入数据?

问题描述

当我使用此代码时,它返回错误“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#sqloracle

解决方案


您的 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了你的字段,因为你没有提到他们的名字。


推荐阅读