gpt4 book ai didi

java - ORA-00905: 缺少关键字 Hibernate 查询 Oracle

转载 作者:行者123 更新时间:2023-11-30 06:43:14 25 4
gpt4 key购买 nike

我的表中有 n 列。我想要选择标准,就好像 column2 中的值为 null,然后根据 column1 选择行,如果 column2 不为 null,则选择基于第 2 列 的值。在引入 CASE WHEN THEN 之前,我有一个很长的查询,该查询工作正常,但是当我得到 ORA-00905在我的查询中添加了案例。示例查询如下:

select * from table where table.testcolumn='some value' and ( case when table.column2 is NULL then  table.column1 = 'value' else table.column2 = 'value' end )

异常(exception):

Caused by: java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1035)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1187)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3386)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3430)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:128)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)

最佳答案

我认为您可以使用替代语句而不使用 case when..:

select * from table 
where table.testcolumn='some value'
and (
(table.column2 is NULL and table.column1 = 'value')
or (table.column2 = 'value')
)

关于java - ORA-00905: 缺少关键字 Hibernate 查询 Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44053412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com