码迷,mamicode.com
首页 > 数据库 > 详细

MySQL 递归获取某文件夹的全路径

时间:2014-12-08 12:20:36      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   on   文件   

传递参数:文件夹ID

 1 DROP FUNCTION IF EXISTS RecursionFolderFullPath;
 2 
 3 CREATE FUNCTION RecursionFolderFullPath(folderId INT(11)) 
 4 RETURNS VARCHAR(1000)
 5 BEGIN
 6 declare fullPath VARCHAR(1000) default ‘‘;
 7 declare parentId INT(11) default 0;
 8 
 9 select concat(folder_name,/,fullPath),folder_parent_id into fullPath,parentId
10 from folder 
11 where folder_id=folderId;
12 
13 WHILE parentId > 0 DO
14 select concat(folder_name,/,fullPath),folder_parent_id into fullPath,parentId
15 from folder 
16 where folder_id=parentId;
17 END WHILE;
18 
19 return fullPath; 
20 END;

调用:

 1 select RecursionFolderFullPath(67); 

结果:

bubuko.com,布布扣

 

MySQL 递归获取某文件夹的全路径

标签:style   blog   http   io   ar   color   sp   on   文件   

原文地址:http://www.cnblogs.com/xcjit/p/4150735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!