存储过程可以执行,转成sql语句就不行,求解!

hgamezoom 2011-07-11 04:57:50
存储过程如下:

create or replace procedure test_milo_add(in_testname in test_milo.testname%type, out_testid out test_milo.testid%type) is
begin

insert into test_milo (testid,testname) values (test_milo_testid.nextval,in_testname);
select crm.test_milo_testid.currval into out_testid from dual;

end test_milo_add;


用.net代码执行该过程,完全正常。

OracleCommand oc = c.CreateCommand();
oc.CommandText = "test_milo_add";
oc.Parameters.Add("in_testname", OracleDbType.Varchar2, entity.TESTNAME, ParameterDirection.Input);
oc.Parameters.Add("out_testid", OracleDbType.Int32,ParameterDirection.Output);
oc.CommandType = CommandType.StoredProcedure;

var rowaffected=oc.ExecuteNonQuery();

但是我想将存储过程中的代码搬到sql语句里直接执行,像这样:

OracleCommand oc = c.CreateCommand();
oc.CommandText = "insert into test_milo (testid,testname) values (test_milo_testid.nextval,:in_testname);select crm.test_milo_testid.currval into :out_testid from dual;";
oc.Parameters.Add("in_testname", OracleDbType.Varchar2, entity.TESTNAME, ParameterDirection.Input);
oc.Parameters.Add("out_testid", OracleDbType.Int32,ParameterDirection.Output);
var rowaffected=oc.ExecuteNonQuery();


就不行了,报错:Oracle.DataAccess.Client.OracleException: ORA-00911: invalid character



求解,应该怎么写才对?前提是我不想使用存储过程,希望直接运行sql语句。

...全文
107 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanzs 2011-07-11
  • 打赏
  • 举报
回复
试试加上begin end

oc.CommandText = "begin insert into test_milo (testid,testname) values (test_milo_testid.nextval,:in_testname);select crm.test_milo_testid.currval into :out_testid from dual; end;";
horizonlyhw 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hgamezoom 的回复:]
不知道楼上是否仔细看过我的问题了?

我如果单独写一句insert into xx values ()是可以执行的,但像这样insert+select的就不行了。
[/Quote]

sorry 才看明白
insert 后面应该直接加select 不能再values了


insert into test_milo (testid,testname) values (test_milo_testid.nextval,:in_testname);select crm.test_milo_testid.currval




是这个意思不?
hgamezoom 2011-07-11
  • 打赏
  • 举报
回复
不知道楼上是否仔细看过我的问题了?

我如果单独写一句insert into xx values ()是可以执行的,但像这样insert+select的就不行了。
horizonlyhw 2011-07-11
  • 打赏
  • 举报
回复
你得写成 inesrt() values具体值的语句
用 OracleCommand oc = c.CreateCommand(); 这个 oracle当然不认识

17,134

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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