当前位置: 首页 > web >正文

开发避坑指南(31):Oracle 11g LISTAGG函数使用陷阱,缺失WITHIN子句解决方案

错误信息

Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-02000: 缺失 WITHIN 关键字

查询语句

使用LISTAGG函数将多行数据合并为单行字符串,如下:

selectt.order_no as orderNo,t.account_no,(select listagg(a.bank_name,',')  from t_account_info a where t.account_no = a.account_no and a.account_type = '01') as bankName,t.payer_name as payername
from t_order_info t
where 1=1
and t.order_no is not null;

错误分析

报以上错误的问题是oracle的版本和listagg的关键字使用不对应,当前用的是oracle 11g ,该版本的listagg使用需要在后面加上within group(order by 字段),如果是oracle 19c的话可以直接使用listagg(字段,‘,’)。

解决办法

将查询语句修改为如下:

selectt.order_no as orderNo,t.account_no,(select listagg(a.bank_name,',') within group (order by a.bank_name) from t_account_info a where t.account_no = a.account_no and a.account_type = '01') as bankName,t.payer_name as payernamefrom t_order_info t
where 1=1
and t.order_no is not null;
http://www.xdnf.cn/news/18561.html

相关文章:

  • Node.js中Express框架入门教程
  • PHY芯片的作用
  • C#_异步编程范式
  • DOLO 上涨:Berachain 生态爆发的前奏?
  • 血管介入医疗AI发展最新方向与编程变革:从外周、神经到冠脉的全面解析
  • 【笔记】动手学Ollama 第七章 应用案例 Agent应用
  • C++的指针和引用:
  • Apache HTTP Server:深入探索Web世界的磐石基石!!!
  • 第5.3节:awk数据类型
  • 部署Qwen2.5-VL-7B-Instruct-GPTQ-Int3
  • linux中的iptables的简介与常用基础用法
  • ES_分词
  • OpenCV图像形态学操作
  • 智能求职推荐系统
  • ES6 面试题及详细答案 80题 (01-05)-- 基础语法与变量声明
  • 在 Linux 中全局搜索 Word 文档内容的完整指南
  • DeepSeek R2难产:近期 DeepSeek-V3.1 发布,迈向 Agent 时代的第一步
  • (LeetCode 面试经典 150 题) 129. 求根节点到叶节点数字之和 (深度优先搜索dfs)
  • windows中bat脚本中一些操作(一)
  • 面试紧张情绪管理:如何保持冷静自信应对挑战
  • ES_预处理
  • 自定义SamOut模型在随机序列生成任务上超越Transformer
  • DINOv3 重磅发布
  • CLruCache::BucketFromIdentifier函数分析
  • k8s集群限制不同用户操作
  • 基于springboot的中医养生管理系统
  • 机器学习-聚类算法
  • 【算法精练】 哈夫曼编码
  • Kotlin-基础语法练习二
  • 【python】python测试用例模板