作者:he恋613_394 | 来源:互联网 | 2023-10-12 20:59
有一张存在上下级关系的function表,parentId表示上级Id,现要查询出上级菜单下的子菜单,每个子菜单显示成以逗号分隔的字符串表结构如下:createtablemenu(
有一张存在上下级关系的function表,parentId表示上级Id,现要查询出上级菜单下的子菜单,每个子菜单显示成以逗号分隔的字符串
表结构如下:
create table menu
(
id int not null,
menucode varchar(100),
menuname varchar(100),
linkadress varchar(500),
parentId char(100) null,
constraint PK_menu primary key (id)
);
查询表数据为:
SELECT a.*,rowid FROM menu a

在oracle中,可以使用wmsys.wm_concat:
SELECT a.*, rowid
FROM menu a
SELECT parentId,
wm_concat(id),
wm_concat(menuname),
wm_concat(linkadress)
FROM menu
group by parentid
查询到的结果集为:
