简体   繁体   中英

How to insert data into Oracle by using where not exists?

When I use this code, it returns an error "SQL command not properly ended" - what am I missing?

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')";

Your SQL Statement is incorrect. You either have to use MERGE statement or change your sql statement to the following:

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');

I have used Field2,Field3,Field4 for your fields, because you didn't mentioned their names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM