首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

依然是Result consisted of more than one row,小弟我要哭了

2012-03-22 
依然是Result consisted of more than one row,我要哭了错误出现在这段代码里面,这是一个存储过程的片段,

依然是Result consisted of more than one row,我要哭了
错误出现在这段代码里面,这是一个存储过程的片段,这段注释掉就不会错,但我还要这功能呢,求大神解答。

SQL code
IF ClassID=-1 THEN      begin        DECLARE  X int;        DECLARE done int;        DECLARE t_cursor cursor for SELECT ID From TopWinCMS_Class where ParentID=0 and IsShowInIndex=1 and LinkUrl =N'' and `ModelID` = ModelID order by `RootID` limit 1;        declare continue handler FOR NOT FOUND SET done = 1;         SET @SQL='';        SET done = 0;        open t_cursor;        while done = 0 do        begin            fetch  t_cursor into X;            SET @SQL=concat('select ID,ModelID,ClassID,ClassName,ContentTitle,Hits,'''' as Content,ColorStyle,FontStyle,UpdateTime,TemplateFileName from VW_',TableName,' where deleted=0 and Pass=1 and ClassID in (',Get_ClassIDs(X),') limit ',TOP);             PREPARE stmt1 FROM @SQL;            EXECUTE stmt1;             DEALLOCATE PREPARE stmt1;        end;        end while;        close t_cursor;    end;END IF;


Get_ClassIDs(X)
代码如下
C# code
delimiter $$drop function if exists Get_ClassIDs;CREATE FUNCTION Get_ClassIDs(iid int)   RETURNS VARCHAR(8000)BEGINDECLARE IDs VARCHAR(255);DECLARE PPt VARCHAR(255);Select concat(`Path`,'%') into PPt FROM TopWinCMS_Class where `ID`=iid;set @IDs='';select concat(@IDs,`ID`,',') into @IDs from TopWinCMS_Class where Path Like  PPt;IF LENGTH(@IDs)>0 THEN set @IDs=left(@IDs,lenth(@IDs)-1);ELSE set @IDs='0';end if;return @IDs;end$$


[解决办法]
Select concat(`Path`,'%') into PPt FROM TopWinCMS_Class where `ID`=iid;
select concat(@IDs,`ID`,',') into @IDs from TopWinCMS_Class where Path Like PPt;

检查这两句的返回,估计是多条记录了。
[解决办法]
别哭了,肯定是下面这2个SQL的问题,你把参数带进去,查查,肯定会有多个记录集。
Select concat(`Path`,'%') into PPt FROM TopWinCMS_Class where `ID`=iid;
select concat(@IDs,`ID`,',') into @IDs from TopWinCMS_Class where Path Like PPt;

热点排行