日期:2014-05-16  浏览次数:20904 次

ABCD四种预处理方式哪种正确?为什么都提示错误?
对预处理还是没有掌握。在下面的运用中,总是提示错误,已试了ABCD四种方式。
请高手救我。


........

open rq_bcf;
while found do
fetch rq_bcf into rq_;
select rq_; /* 监测rq_值 */
if found=true then


begin


declare bpld_ MEDIUMINT;
declare spld_ MEDIUMINT;
declare zxp_ MEDIUMINT;


#select sum(ss) into bpld_ from bm where bs='b';
#select sum(ss) into spld_ from bm where bs='s';
#select sum(ss) into zxp_ from bm where bs='z';

select bm,rq_; /* 监测bm,rq_值 */



# A:
#set @asql1=concat('select sum(ss) into ',bpld_,' from ',bm,' where bs=b and rq= ',rq_,';');
# PREPARE STMT1 FROM @asql1;
  # EXECUTE STMT1;
#set @asql2=concat('select sum(ss) into ',spld_,' from ',bm,' where bs=s and rq= ',rq_,';');
  #PREPARE STMT2 FROM @asql2;
  # EXECUTE STMT2;
#set @asql3=concat('select sum(ss) into ',zxp_,' from ',bm,' where bs=z and rq= ',rq_,';');
  #PREPARE STMT3 FROM @asql3;
  # EXECUTE STMT3;


# B:
#set @asql1=concat('select sum(ss) into ? from ',bm,' where bs=b and rq=?;');
  #PREPARE STMT1 FROM @asql1;
#set @bpld_=bpld_;
#set @rq_=rq_;
  # EXECUTE STMT1 using @bpld_, @rq_;
#set @asql2=concat('select sum(ss) into ? from ',bm,' where bs=s and rq=?;');
  #PREPARE STMT2 FROM @asql2;
#set @spld_=spld_;
#set @rq_=rq_;
  # EXECUTE STMT2 using @spld_, @rq_;
#set @asql3=concat('select sum(ss) into ? from ',bm,' where bs=z and rq=?;');
  #PREPARE STMT3 FROM @asql3;
#set @zxp_=zxp_;
#set @rq_=rq_;
  # EXECUTE STMT3 using @zxp_, @rq_;


# C:
#set @asql1=concat('select sum(ss) into ',bpld_,' from ',bm,' where bs=b and rq=?;');
  #PREPARE STMT1 FROM @asql1;
#set @rq_=rq_;
  # EXECUTE STMT1 using @rq_;
#set @asql2=concat('select sum(ss) into ',spld_,' from ',bm,' where bs=s and rq=?;');
# PREPARE STMT2 FROM @asql2;
#set @rq_=rq_;
  # EXECUTE STMT2 using @rq_;
#set @asql3=concat('select sum(ss) into ',zxp_,' from ',bm,' where bs=z and rq=?;');
# PREPARE STMT3 FROM @asql3;
#set @rq_=rq_;
  # EXECUTE STMT3 using @rq_;


# D:
set @asql1=concat('select sum(ss) into bpld_ from ',bm,' where bs=b and rq=?;');
  PREPARE STMT1 FROM @asql1;
set @rq_=rq_;
  EXECUTE STMT1 using @rq_;
set @asql2=concat('select sum(ss) into spld_ from ',bm,' where bs=s and rq=?;');
  PREPARE STMT2 FROM @asql2;
set @rq_=rq_;
  EXECUTE STMT2 using @rq_;
set @asql3=concat('select sum(ss) into zxp_ from ',bm,' where bs=z and rq=?;');
  PREPARE STMT3 FROM @asql3;
set @rq_=rq_;
  EXECUTE STMT3 using @rq_;

........


以上语句的背景见http://topic.csdn.net/u/20120611/16/8f42cbcf-92f1-4be1-b208-59f7816ea3de.html
是嵌套在以上帖子的楼主的倒数第二段中的。
游标等均已定义,但是D方式仍提示:ERROR 1327 (42000): Undeclared variable: bpld_


不想发重复帖,但是原帖没人及时回复,故开新帖。
谢谢!

------解决方案--------------------
set @asql1=concat('select sum(ss) into @bpld_ from ',bm,' where bs=b and rq=?;');
PREPARE STMT1 FROM @asql1;
execute stmt1;
select @bpld_;
------解决方案--------------------
给出你完整的语句从 create procedure 开始到结束,然后把错误信息也完成贴出以供分析。