0

此语句在 SQLDeveloper(Oracle DB) 中执行时完美运行。

select id,name,street,post_code,town,phone_number,web_site,email,short_description,    
description, latitude,longitude,external_id,facebook_page_id 
FROM poi WHERE ( 6371 * acos( cos( radians( 5 ) ) * cos( radians( latitude ) ) * cos(    
radians( longitude ) - radians( 3 ) ) + sin( radians( 5 ) ) * sin( radians( latitude ) ) ) ) <= 1000000 ; 

如果我通过 java 查询执行它:

if (requestedDistance) {
String raw = "SELECT         
id,name,street,post_code,town,phone_number,web_site,email,short_description, description,             
latitude,longitude,external_id,facebook_page_id"
+ " FROM poi WHERE ( 6371 * acos( cos( radians( "
+ posLatitude.toString()
+ " ) ) * cos("
+ " radians( latitude ) ) * cos( radians( longitude ) -"
+ " radians( "
+ posLongitude.toString()
+ " ) ) + sin( radians( "
+ posLatitude.toString()
+ " ) ) * sin( radians( latitude"
+ " ) ) ) ) <= "
+ thresholdDistance.toString() + " ;";

日志中出现以下异常:

    at java.lang.Thread.run(Thread.java:679) Caused by: javax.persistence.PersistenceException: Query threw

SQLException:ORA-00920:无效的关系运算符绑定值:[] 查询是:选择 id、名称、街道、邮政编码、城镇、电话号码、网站、电子邮件、简短描述、描述、纬度、经度、external_id、facebook_page_id FROM poi WHERE(6371 * acos(cos(弧度(5))* cos(弧度(纬度))* cos(弧度(经度)-弧度(3))+ sin(弧度(5))* sin(弧度(纬度))))< = 1000000 ;

    at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:834)
    at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:814)
    at com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:229)
    at com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:96)
    at com.avaje.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:291)
    at com.avaje.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1521)
    at com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery.findList(DefaultOrmQuery.java:902)
    at com.infonova.experimedia.services.ServiceController.getPois(ServiceController.java:113)
    ... 34 more Caused by: java.sql.SQLSyntaxErrorException: ORA-00920: invalid relational operator

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
    at com.sun.gjc.spi.jdbc40.PreparedStatementWrapper40.executeQuery(PreparedStatementWrapper40.java:642)
    at com.avaje.ebeaninternal.server.query.CQuery.prepareBindExecuteQuery(CQuery.java:401)
    at com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:193)
    ... 39 more

|#]

从日志文件中复制语句并在 sqldeveloper 中再次执行它会返回一个有效的输出。

感谢您的每一个帮助!

尼科

4

2 回答 2

1

删除;末尾的 - 它是 SQLDeveloper/SQLPlus 的终止符,不是 SQL 语法的一部分。

于 2013-11-06T14:07:43.637 回答
0

ORA-00920无效的关系运算符原因:输入了无效或缺少关系运算符的搜索条件。

操作:包括一个有效的关系运算符,例如 =、!=、^=、<>、>、<、>=、<=、ALL、ANY、[NOT] BETWEEN、EXISTS、[NOT] IN、IS [NOT]条件中的 NULL 或 [NOT] LIKE。

于 2013-11-06T14:10:26.753 回答