CREATE FUNCTION topoFolderFun(folderIdTmp bigint(20)) RETURNS varchar(1000) DETERMINISTIC begin declare sTemp varchar(1000); declare sTempChd varchar(1000); set sTemp = ''; set sTempChd = cast(folderIdTmp as char); lable : loop set sTemp = concat(sTemp,',',sTempChd); select group_concat(folderId) into sTempChd from topofolder where find_in_set(superiorId, sTempChd) > 0; if found_rows()=0 or sTempChd is null then return substring(sTemp,2); end if; end loop; end$$
DETERMINISTIC
begin
declare sTemp varchar(1000);
declare sTempChd varchar(1000);
set sTemp = '';
set sTempChd = cast(folderIdTmp as char);
lable : loop
set sTemp = concat(sTemp,',',sTempChd);
select group_concat(folderId) into sTempChd from topofolder where find_in_set(superiorId, sTempChd) > 0;
if found_rows()=0 or sTempChd is null then
return substring(sTemp,2);
end if;
end loop;
end$$
我说的意思是 不写循环 就单独执行一次都不行
唉 已经找到个方法 直接写sql语句查询能得到结果了
不过没弄清楚这个问题 还是很不爽
就可以了
就是把where后面改成 GoodsTypeID= goodsTypeId 直接用传入的参数 结果也不对
参考一下这个贴子的提问方式http://bbs.csdn.net/topics/320211382
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。