没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
存储过程:递归查树节点
DELIMITER //
drop procedure if exists ndLChild//
/* iid 递归父节点 , layer 允许递归深度 */
CREATE PROCEDURE ndLChild(iid bigint(20),layer bigint(20))
BEGIN
/*创建接受查询的临时表 */
create temporary table if not exists tmp_table(id bigint(20),name
varchar(50)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*最高允许递归数*/
SET @@max_sp_recursion_depth = 99 ;
call iterative(iid,layer);/*核心数据收集*/
select * from (select id,name from mytree where id=iid union
select id,name from tmp_table) tmp;
/* 展现 */
drop temporary table if exists tmp_table ;/*删除临时表*/
END;//
DELIMITER ;
DELIMITER //
drop procedure if exists iterative //
CREATE PROCEDURE iterative(iid bigint(20),layer bigint(20))
BEGIN
declare tid bigint(20) default -1 ;
declare tname varchar(50) character set utf8;
/* 游标定义 */
declare cur1 CURSOR FOR select id,name from mytree where
pid=iid ;
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET tid =
null;
/* 允许递归深度 */
if layer>0 then
OPEN cur1 ;
FETCH cur1 INTO tid,tname ;
WHILE ( tid is not null )
DO
/* 核心数据收集 */
insert into tmp_table values(tid,tname);
call iterative(tid,layer-1);
资源评论
whg0527
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功