浏览代码

教研分析脚本

wangliang 2 年之前
父节点
当前提交
d2503d77fa
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      teachcloud-report-business/src/main/resources/db/3、init-function.sql

+ 20 - 0
teachcloud-report-business/src/main/resources/db/3、init-function.sql

@@ -0,0 +1,20 @@
+-- ----------------------------
+-- Function structure for getRootChildId
+-- ----------------------------
+delimiter //
+DROP FUNCTION IF EXISTS `getRootChildId`;
+CREATE FUNCTION `getRootChildId`(rootId bigint) RETURNS varchar(1000) CHARSET utf8mb4
+    DETERMINISTIC
+BEGIN
+    DECLARE ptemp VARCHAR(1000);
+    DECLARE ctemp VARCHAR(1000);
+    SET ptemp = '#';
+    SET ctemp = cast(rootId as CHAR);
+    WHILE ctemp IS NOT NULL DO
+      SET ptemp = concat(ptemp, ',', ctemp);
+SELECT group_concat(id) INTO ctemp FROM sys_org WHERE FIND_IN_SET(parent_id, ctemp) > 0;
+END WHILE;
+RETURN ptemp;
+END;
+//
+delimiter ;