C#中如何执行多条Oracle的SQL语句(不用存储过程和事务)

WardenMoon 2008-05-08 05:55:14
在改造一个项目的时候发现,项目里面有比较多的批sql(在SQL Server库 + System.Data.SqlClient是可以执行多条SQL语句),改造成Oracle的SQL语句之后发现不能通过OracleClient来执行,无论是command的executenoquery()还是scalar()等方法。

需要执行的SQL语句如下:
delete from t1 where t1.f1='11';
delete from t2 where t2.f1='22';
select f1 from t3 where t3.f1='33';

要求:不使用存储过程或者分条包装成事务(因为原来代码结构的限制)

各位哥哥有什么好办法么?
...全文
1118 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinjazz 2008-05-09
  • 打赏
  • 举报
回复
用begin end试试
PowerFedora 2008-05-09
  • 打赏
  • 举报
回复
string sqlCmd="begin delete from t1 where t1.f1='11'; delete from t2where t2.f1='22'; select f1 from t3 where t3.f1='33';end"
hsxgodkiller 2008-05-09
  • 打赏
  • 举报
回复
分号可以的,我用过的
以begin开始,以end;结尾(end后的分号不能省),中间的每个sql语句要以分号;结尾
problem2050 2008-05-09
  • 打赏
  • 举报
回复
用循环执行吧
problem2050 2008-05-09
  • 打赏
  • 举报
回复
4楼的不能执行,我试过,我也碰到过这种问题,那种语句在PLSQL软件就可以执行,放到C#代码是就不行.
ouhou 2008-05-09
  • 打赏
  • 举报
回复
楼上正确
EvilYangs 2008-05-09
  • 打赏
  • 举报
回复
string sqlCmd="delete from t1 where t1.f1='11'; delete from t2where t2.f1='22'; select f1 from t3 where t3.f1='33';"

goding 2008-05-09
  • 打赏
  • 举报
回复
command.cmdtext="delete from t1 where t1.f1='11'";
command.executenoquery();
command.cmdtext="delete from t2 where t2.f1='22'";
command.executenoquery();
...
...
starlessnt 2008-05-09
  • 打赏
  • 举报
回复
嗯 ,代码贴上来帮你Look一下..

你说的问题意思上没问题.
sunke5843323 2008-05-09
  • 打赏
  • 举报
回复
应该可以得吧,LZ command怎么写的
WardenMoon 2008-05-09
  • 打赏
  • 举报
回复
感谢各位的回答,今天和同事研究了半天,发现问题是这样的:
.NET自己提供的System.Data.OracleClient.dll不能执行多条SQL语句,也不能执行标准PL/SQL块(begin....end;);

而Oracle自己提供的驱动(ODBC; OleDb;OracleNet)都可以执行标准的PL/SQL块,也就是说可以执行
多条Inser、Delete、Update语句。

可是问题又出来,多条Select语句是不能执行的,PL/SQL块里面Select必须into一个变量,
看来只能改程序,一个个执行select了。
2303191 2008-05-09
  • 打赏
  • 举报
回复
不加begin end直接加分号也是可以的
problem2050 2008-05-09
  • 打赏
  • 举报
回复
没用过begin end
这样应该可以.

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧