MySQL自定义函数示例

BEGIN
  DECLARE oTemp VARCHAR (20000) ;
  
  DECLARE oTempChild VARCHAR (10000) ;
  
  SET oTemp = '' ;
  
  SET oTempChild = CAST(orgid AS CHAR) ;
  
  WHILE
    oTempChild IS NOT NULL DO SET oTemp = CONCAT(oTemp, ',', oTempChild) ;
    
    SELECT 
      GROUP_CONCAT(id) INTO oTempChild 
    FROM
      framework_org 
    WHERE FIND_IN_SET(parent_id, oTempChild) > 0 ;
    
  END WHILE ;
  
  RETURN oTemp ;
  
END

 

你可能感兴趣的:(MySQL)