ERROR 1265(01000):为列' childId'截断数据在第1行

时间:2016-12-29 11:22:09

标签: mysql sql hierarchical-data

表型号:

CREATE TABLE `employee` (
  `empId` int(11) NOT NULL,
  `managerEmpId` int(11) DEFAULT NULL,
  PRIMARY KEY (`empId`)
)

数据记录:

| empId | managerEmpId |
|  1010 |         1022 |
|  1013 |         1022 |
|  1014 |         1023 |
|  1015 |         1023 |
|  1016 |         1023 |
|  1017 |         1023 |
|  1022 |         1023 |
|  1001 |         1021 |
|  1006 |         1008 |
|  1007 |         1024 |
|  1008 |         1024 |
|  1009 |         1022 |
|  1011 |         1022 |
|  1012 |         1011 |
|  1018 |         1021 |

我需要一名经理,包括他的报告人的报告人。

我写的查询是:

CREATE PROCEDURE get_tree (IN parentId int)
  BEGIN
      declare childId int;

      select empId into childId from (SELECT GROUP_CONCAT(empId SEPARATOR ',') as empId FROM employee WHERE managerEmpId IN (parentId)) child;

      select childId;

      create TEMPORARY table IF NOT EXISTS temp_table as (select * from employee where empId=parentId);

      WHILE childId != null DO
        insert into temp_table select * from employee WHERE empId IN (childId);
        SET parentId=childId;
        select parentId;
        select empId into childId FROM (SELECT GROUP_CONCAT(empId SEPARATOR ',') as empId FROM employee WHERE managerEmpId IN (parentId))child;
      END WHILE;

    select * from temp_table;
  END//

我收到错误:

  

ERROR 1265(01000):数据被截断为列' childId'在第1行

任何人都可以帮助我。

0 个答案:

没有答案