网站首页 > 技术文章 正文
oracle的listagg函数可以把多行转为一个字符串,用起来很方便,示例如下:
with t1 as (select '001' as itemcode,'苹果' as itemname,'01' as itemtype from dual
union all select '002','梨','01' from dual union all select '003','香蕉','01' from dual union all select '004','桔子','01' from dual
union all select '005','土豆','02' from dual union all select '006','白菜','02' from dual union all select '007','黄瓜','02' from dual)
select listagg(t1.itemcode||t1.itemname,',') WITHIN GROUP(ORDER BY t1.itemtype) as itemlist from t1
;
with t1 as (select '001' as itemcode,'苹果' as itemname,'01' as itemtype from dual
union all select '002','梨','01' from dual union all select '003','香蕉','01' from dual union all select '004','桔子','01' from dual
union all select '005','土豆','02' from dual union all select '006','白菜','02' from dual union all select '007','黄瓜','02' from dual)
select t1.itemtype, listagg(t1.itemcode||t1.itemname,',') WITHIN GROUP(ORDER BY t1.itemtype) as itemlist from t1
group by t1.itemtype
;
20250720
- 上一篇: oracle之基本操作学习笔记
- 下一篇: 程序员面试中问到的Oracle常用数据类型
猜你喜欢
- 2025-08-01 程序员面试中问到的Oracle常用数据类型
- 2025-08-01 oracle之基本操作学习笔记
- 2024-10-30 oracle数据库优化:合理使用索引 oracle数据库索引类型和原理
- 2024-10-30 详解Oracle数据库OutLines的使用--控制SQL执行计划的机制
- 2024-10-30 Oracle 数据库日常巡检之检查Oracle相关资源的使用情况
- 2024-10-30 ORACLE强制使用索引要点 oracle加hint强制走索性
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- oracle面试 (55)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)