建表:
create table t_dept
(
  n_dept_id int(11) not null auto_increment,
  n_keyin_id int(11) not null,
  n_dept_supervisor_id int(11) not null,
  n_dept_contact_id int(11),
  n_dept_father_id int(11),
  vc_dept_name varchar(4000) not null,
  vc_dept_tel varchar(4000),
  vc_note varchar(8000),
  dt_del_time datetime,
  primary key (n_dept_id)
);
其中:n_dept_id自己的ID, n_dept_father_id父ID函数:
CREATE DEFINER=`root`@`localhost` FUNCTION `getChildLst`(rootId INT) RETURNS text CHARSET gbk
BEGIN
DECLARE sTemp text;
DECLARE sTempChd text; SET sTemp = '$';
 SET sTempChd =cast(rootId as char);
WHILE sTempChd is not null DO
  SET sTemp = concat(sTemp,',',sTempChd);
  SELECT group_concat(n_dept_id) INTO sTempChd FROM t_dept where FIND_IN_SET(n_dept_father_id,sTempChd)>0;
 END WHILE;
 RETURN sTemp;
 END;
测试: select * from t_dept
  where FIND_IN_SET(n_dept_id, getChildLst(4));
显示了id为4的那一行。但是如果把4换成1.就会报错:data too long for column for 'sTemple'参数4和1唯一的不同是,没有父ID为4的行。但是有父ID为1的行。
求解。