java - ORA-00907: 在 Java 中使用 % 通配符时缺少右括号
问题描述
在我在子句中使用%
通配符之前,我遇到问题的查询工作正常。LIKE
:-
这很好(从 Java 打印):-
select acc.*, service.*
from com_accounts acc
left join com_subscriptions service on acc.cust_id = service.cust_id
where 1=1 and UPPER(acc.first_name) LIKE UPPER(?)
这引发了一个错误(从 Java 代码打印):-
select acc.*, service.*
from com_accounts acc
left join com_subscriptions service on acc.cust_id = service.cust_id
where 1=1 and UPPER(acc.first_name) LIKE UPPER('%'?'%')
java.sql.SQLSyntaxErrorException: ORA-00907: 缺少右括号
解决方案
使用此查询,您将只有三个连续的字符串,它们之间没有运算符,正如您所见,这不是 Oracle 中的合法语法。使用运算符连接它们||
应该可以解决问题:
select acc.*, service.*
from com_accounts acc
left join com_subscriptions service on acc.cust_id = service.cust_id
where 1=1 and UPPER(acc.first_name) LIKE UPPER('%' || ? || '%')
-- Here --------------------------------------------^----^
推荐阅读
- firebase - 更新firestore中文档的createdAt和updatedAt日期字段的正确方法是什么?
- angular - 角度 7 中的单击事件未触发输入类型复选框
- python - 如果列中的值与 2 个值中的至少一个不匹配,则删除行
- vhdl - 以太网媒体独立接口管理控制导致“链路断开”
- powershell - 具有运行空间而不是 foreach 循环的多线程
- github - 如何一次更新多个提交的状态
- c# - 如何从测试项目中读取 API 项目的启动设置?
- winapi - SspiPromptForCredentials 目标名称
- javascript - Three.js 360 图像 - 纹理标记为更新,但图像不完整
- javascript - 阿拉伯语脚本在 Google 的开发者工具模拟器上呈现不正确