Home >Database >Mysql Tutorial >MySQL中实现类似Oracle的SYS_CONNECT_BY_PATH功能

MySQL中实现类似Oracle的SYS_CONNECT_BY_PATH功能

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:47:322034browse

Oracle中的SYS_CONNECT_BY_PATH函数为开发带来了便利,MySQL中如何实现类似的功能呢?

Oracle中的SYS_CONNECT_BY_PATH函数为开发带来了便利,,MySQL中如何实现类似的功能呢?

DELIMITER $$
 CREATE FUNCTION `getParentList` (rootId VARCHAR (50)) RETURNS VARCHAR (1000)
 BEGIN
  DECLARE sParentList VARCHAR (1000) ;
  DECLARE sParentTemp VARCHAR(1000);
  SET sParentTemp =CAST(rootId AS CHAR);
  WHILE sParentTemp IS NOT NULL DO
  IF (sParentList IS NOT NULL) THEN
  SET sParentList = CONCAT(sParentTemp,'/',sParentList);
  ELSE
  SET sParentList = CONCAT(sParentTemp);
  END IF;
 SELECT GROUP_CONCAT(parent_module_id) INTO sParentTemp FROM TOP_SYS_MODULE WHERE FIND_IN_SET(module_id,sParentTemp)>0;
 END WHILE;
 RETURN sParentList;
 END$$
 DELIMITER ; 


SELECT module_id,parent_module_id,getParentList(module_id) FROM TOP_SYS_MODULE;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn