DELIMITER //
drop procedure if exists sys_columns_nodes//
create procedure sys_columns_nodes(in rootid int)
begin
declare stemp varchar(1000);/*定义一个临时字段来存放所有的类别与子类别*/
declare stempchd varchar(1000);/*定义一个临时字段,来得到当前类别的子类别*/
set stemp = '$';
set stempchd =rootid;
/*set stempchd =cast(rootid as char); */
while stempchd>0 do
set stemp = concat(stemp,',',stempchd);/*将以前类别与现在查询类别进行合并*/
/*将每次查到的子id形成一个字符组,放到stempchd里,如果stempchd为null就停止循环*/
select group_concat(id) into stempchd from sys_columns where find_in_set(parent_id,stempchd)>0;
end while;
delete from sys_columns where find_in_set(id,stemp);
end;
//
DELIMITER ;
/* 1 是id值*/
call sys_columns_nodes(1);