简体   繁体   English

Oracle合并语句ORA-01036错误C#ado.net

[英]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. 当我将命令的BindByName属性设置为true时,我的合并语句中遇到了隐秘的ORA-01036错误。 If I set BindByName to false, it makes matter worse, and actually gives incorrect results, without giving error message. 如果将BindByName设置为false,则情况会更糟,并且实际上会给出错误的结果,而不会给出错误消息。

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 . 经过研究,结果发现您无法重复查询中的关键参数,而是需要对usings语句中的关键变量使用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 . 经过研究,结果发现您无法重复查询中的关键参数,而是需要对usings语句中的关键变量使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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