找到父節點下的所有子節點(包括子節點)
阿新 • • 發佈:2017-07-20
新增 not tab clas ren while blog url pkg
CREATE TABLE `tab_menu` ( `MU_ID` int(10) NOT NULL AUTO_INCREMENT COMMENT ‘主鍵‘, `MU_NAME` varchar(255) NOT NULL COMMENT ‘菜單名‘, `MU_CODE` varchar(100) DEFAULT NULL COMMENT ‘菜單編碼‘, `MU_CHAIN_NAME` varchar(255) NOT NULL COMMENT ‘菜單全名‘, `MU_PARENT_ID` int(10) NOT NULL COMMENT ‘上級菜單ID‘, `MU_URL`varchar(255) NOT NULL COMMENT ‘菜單URL‘, `STATUS` smallint(1) NOT NULL DEFAULT ‘1‘ COMMENT ‘狀態;0:未啟用 1:已啟用,默認為1‘, `MU_ELEMENT_TYPE` varchar(40) NOT NULL COMMENT ‘所屬元素類型‘, `MU_SCOPE` varchar(20) NOT NULL DEFAULT ‘common‘ COMMENT ‘菜單作用範圍;‘, `CREATE_USER_ID` int(11) NOT NULL COMMENT ‘創建用戶ID‘, `CREATE_TIME`datetime NOT NULL COMMENT ‘創建時間‘, `UPDATE_USER_ID` int(11) DEFAULT NULL COMMENT ‘修改用戶ID‘, `UPDATE_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘修改時間‘, `VERSION_NUMBER` int(11) NOT NULL DEFAULT ‘0‘ COMMENT ‘版本號:新增資料為 0,每次修改加 1‘, PRIMARY KEY (`MU_ID`),KEY `idx_menu_url` (`MU_URL`) ) ENGINE=InnoDB AUTO_INCREMENT=2040101 DEFAULT CHARSET=utf8 COMMENT=‘菜單‘;
CREATE DEFINER=`ggs`@`%` FUNCTION `pkg_pm_fun_get_children_branch`(menu_id int(10)) RETURNS text CHARSET utf8 COLLATE utf8_bin begin declare menu_ids TEXT; declare tmp_menu_ids text; set tmp_menu_ids =‘$‘; set menu_ids = cast(menu_id as char); while menu_ids is not null do set tmp_menu_ids = concat(tmp_menu_ids,‘,‘,menu_ids); select group_concat(mu_id) into menu_ids from tab_menu where find_in_set(mu_parent_id,menu_ids) > 0; end while; return tmp_menu_ids; end
找到父節點下的所有子節點(包括子節點)