网站首页 > 技术文章 正文
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强制走索性
你 发表评论:
欢迎- 644℃几个Oracle空值处理函数 oracle处理null值的函数
- 634℃Oracle分析函数之Lag和Lead()使用
- 627℃0497-如何将Kerberos的CDH6.1从Oracle JDK 1.8迁移至OpenJDK 1.8
- 625℃Oracle数据库的单、多行函数 oracle执行多个sql语句
- 620℃Oracle 12c PDB迁移(一) oracle迁移到oceanbase
- 608℃【数据统计分析】详解Oracle分组函数之CUBE
- 599℃最佳实践 | 提效 47 倍,制造业生产 Oracle 迁移替换
- 584℃Oracle有哪些常见的函数? oracle中常用的函数
- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- 前端获取当前时间 (50)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)