下面这个存储过程执行不过,mysql给出的错误信息实在不很准确,第一次用mysql数据库,请各位帮忙看看这个存储过程有什么问题:drop procedure if exists PublicBlog //create procedure PublicBlog(Fid int,NickName char(16),Subject char(80),PubDate int,Message mediumtext,UserIp char(15))
begin
START TRANSACTION;
   declare UserId int;
   select uid into UserId from cdb_members where username=NickName;
   insert into cdb_threads
(fid,iconid,typeid,readperm,price,author,authorid,subject,dateline,lastpost,lastposter,views,replies,displayorder,highlight,digest,rate,blog,special,attachment,subscribed,moderated,closed,itemid,supe_pushstatus) values
(Fid,0,0,0,0,NickName,UserId,Subject,PubDate,PubDate,NickName,0,0,0,0,0,0,0,0,0,0,0,0,0,0);   declare Tid int;
   select Last_Insert_Id() into Tid;
   insert into cdb_mythreads (uid,tid,dateline) values (UserId,Tid,PubDate);   insert into cdb_posts
(fid,tid,first,author,authorid,subject,dateline,message,useip,invisible,anonymous,usesig,bbcodeoff,smileyoff) values 
(Fid,Tid,1,NickName,UserId,Subject,PubDate,Message,UseIp,0,0,0,-1,-1);
   
   declare Pid int;
   select Last_Insert_Id() into Pid;
   insert into cdb_myposts (uid,tid,pid,position,dateline) values (UserId,Tid,Pid,1,PubDate);   declare Lastpost char(128);
   set Lastpost=Tid + ' ' + Subject + ' ' + PubDate + ' ' + NickName;
   update cdb_forums set threads=threads+1,posts=posts+1,todayposts=todayposts+1,lastpost=Lastpost    where fid=Fid;COMMIT;
end //call PublicBlog(12,'ph','test','1111111111','message','127.0.0.1')

解决方案 »

  1.   

    declare UserId int;
       select uid into UserId from cdb_members where username=NickName;
       insert into cdb_threads
    (fid,iconid,typeid,readperm,price,author,authorid,subject,dateline,lastpost,lastposter,views,replies,displayorder,highlight,digest,rate,blog,special,attachment,subscribed,moderated,closed,itemid,supe_pushstatus) values
    (Fid,0,0,0,0,NickName,UserId,Subject,PubDate,PubDate,NickName,0,0,0,0,0,0,0,0,0,0,0,0,0,0);这一段不加事务处理就可以执行通过,加上就报错,奇怪
      

  2.   

    应该把变量的声明集中放在程序体的开头,
    MySQL的语法比较弱。
      

  3.   

    select uid into UserId from cdb_members where username=NickName;
    NickName不是个列名吗? 怎么还成了username.
      还有它报的什么错?
      

  4.   

    marcowind(marcowind) 
    thank you!