简体   繁体   中英

Oracle Merge statement ORA-01036 error c# ado.net

This is more of a caution than a question, as it will save someone a lot of headaches if they encounter this situation.

I faced the cryptic ORA-01036 error in my merge statement when I set command's BindByName property to true. If I set BindByName to false, it makes matter worse, and actually gives incorrect results, without giving error message.

After some research, it turns out you, cannot repeat the key parameters in the query, rather you need to use the key variables in the using statement for key variables in the inserts . Here is a simple illustration.

merge into rsvp r using (select :id as id from dual) d on (r.id=d.id)
 when matched then update set rsvp_date=sysdate
 when not matched then insert (id,rsvp_date) values (:id, sysdate)

This will give you error. The fix is to change the insert statement on the last line to:

   when not matched then insert (id,rsvp_date) values (d.id, sysdate)

After some research, it turns out you, cannot repeat the key parameters in the query, rather you need to use the key variables in the using statement for key variables in the inserts . Here is a simple illustration.

merge into rsvp r using (select :id as id from dual) d on (r.id=d.id)
 when matched then update set rsvp_date=sysdate
 when not matched then insert (id,rsvp_date) values (:id, sysdate)

This will give you error. The fix is to change the insert statement on the last line to:

   when not matched then insert (id,rsvp_date) values (d.id, sysdate)

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