存储过程中给变量赋值

zhao8848jun 2009-02-20 03:16:30
create procedure myProc(v_JQ varchar(50),out flg int)
begin
declare SYID,JQID,MyNewId int default 0;
set flg=1;
select id into JQID from insorder where insDocumentId=v_JQ and `status`='新数据' limit 0,1;
set flg=JQID;
end

在MYSql查询分析器里执行运行正常。可是通过C#程序调用该存储过程,flg则为0,并且select id是有值的,如果set flg=v_JQ 则返回我传入的值
...全文
563 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhao8848jun 2009-02-24
  • 打赏
  • 举报
回复
问题已经解决,原来是status`='新数据' 或 financialVerifyPerson='赵全华'中中文的问题,需要在中文前面加_utf8来转换一下
ACMAIN_CHM 2009-02-20
  • 打赏
  • 举报
回复
create procedure myProc(v_JQ varchar(50),out flg int) 
begin
declare SYID,JQID,MyNewId int default 0;
set flg=1;
select id into JQID from insorder where insDocumentId=v_JQ and `status`='新数据' limit 0,1;
set flg=JQID;
end


…… 
Cmd.CommandText = "pop_test";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters[0].Direction = ParameterDirection.Output;
if (Cmd.Connection.State == 0)
Cmd.Connection.Open();
Cmd.ExecuteNonQuery();
label1.Text += Cmd.Parameters[0].Value + "\r\n";


看一下,你的myProc有几个参数???你传了几个参数? 参数[0]对应的是哪个参数?

9楼 更是不知道你想说什么?

你自己运行一下
select 1 from insorder where id=21053;
select 1 from insorder where financialVerifyPerson='赵全华';
不就什么都知道了,根本没有 '赵全华'

zhao8848jun 2009-02-20
  • 打赏
  • 举报
回复
现在又检测到不是关键字的问题
begin
if exists(select 1 from insorder where id=21053) then
set flg=10;
else
set flg=11;
end if;
end
上面返回10
而下面的则返回11
begin
if exists(select 1 from insorder where financialVerifyPerson='赵全华') then #financialVerifyPerson字段中有赵全华这样的记录
set flg=10;
else
set flg=11;
end if;
end
zhao8848jun 2009-02-20
  • 打赏
  • 举报
回复
……
Cmd.CommandText = "pop_test";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("?flg", MySqlDbType.Int16);//, 50);
Cmd.Parameters[0].Direction = ParameterDirection.Output;
if (Cmd.Connection.State == 0)
Cmd.Connection.Open();
Cmd.ExecuteNonQuery();
label1.Text += Cmd.Parameters[0].Value + "\r\n";
……
zhao8848jun 2009-02-20
  • 打赏
  • 举报
回复
……
Cmd.CommandText = "pop_test";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters[0].Direction = ParameterDirection.Output;
if (Cmd.Connection.State == 0)
Cmd.Connection.Open();
Cmd.ExecuteNonQuery();
label1.Text += Cmd.Parameters[0].Value + "\r\n";
……
ACMAIN_CHM 2009-02-20
  • 打赏
  • 举报
回复
和数据库和存储过程应该没有关系,是你C中调用传参数方式的问题。

猜不出你C中是如何调用的,所以也无法回答。

问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧
zhao8848jun 2009-02-20
  • 打赏
  • 举报
回复
数据库是别人设计的,并且已经多处应用了,修改字段名,不是很实现
WWWWA 2009-02-20
  • 打赏
  • 举报
回复
应该加``就可以了,修改字段名试试
zhao8848jun 2009-02-20
  • 打赏
  • 举报
回复
在查询分析器里是正确的
可是用程序调用 就不正确了
刚才我查出原因了,是`status` 这个关键字的问题的,我如果把这个条件去掉,就正确了,可现在这个条件不能去,并且这个字段名是MYSql中的关键字,
有解决办法吗?
WWWWA 2009-02-20
  • 打赏
  • 举报
回复
create procedure myProc(v_JQ varchar(50),out flg int)
begin
declare SYID,JQID,MyNewId int default 0;
select id into flg from insorder where insDocumentId=v_JQ and `status`='新数据' limit 0,1;
end

call myproc('123',@ee);
select @ee

结果是否正确
zhao8848jun 2009-02-20
  • 打赏
  • 举报
回复
现在测试用程序执行存储过程
if exists(select 1 from insorder where `status`='新数据' ) then
set flg=10;
else
set flg=11;
end if;
永远返回11
而直接在查询分析器里执行select 1 from insorder where `status`='新数据' 出现1

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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