日期:2014-05-17  浏览次数:20831 次

修改特别慢
update   sq_trq   set   ylsql=10,nlsql=10   where   xh=1010   and   rq=to_date( '2007-01-01 ', 'yyyy-MM-dd ')
这条语句,我在sql*plus里执行特别快,但是在C#程序里执行特别慢.
程序代码如下:
sql= "update   sq_trq   set   ylsql= "+ylsql+ ",nlsql= "+nlsql+ "   where   xh= "+mt0.Rows[0][0]+ "   and   rq=to_date( ' "+rq+ " ', 'yyyy-MM-dd ') ";
cmd=new   OracleCommand(sql,conn);
cmd.ExecuteNonQuery();

为什么?

------解决方案--------------------
建议用绑定变量重写SQL语句
update sq_trq set ylsql=:x1,nlsql=:x2 where xh=:x3 and rq=:x4

------解决方案--------------------
楼上说的对,使用绑定变量,再看看执行计划

update sq_trq set ylsql=:x1,nlsql=:x2 where xh=:x3 and rq=:x4