oracle jdbc无效编号

问题描述 投票:0回答:1

我正在尝试执行以下查询:

String query =  "select NUMERO_CHAUFFEUR, avg(DISTANCE) as DISTANCE " +
                "from " +
                "(select NUMERO_CHAUFFEUR, " +
                "6387.7 * ACOS((sin(LATITUDE_DEPART / 57.29577951) * SIN(LATITUDE_ARRIVEE / 57.29577951)) + " +
                "(COS(LATITUDE_DEPART / 57.29577951) * COS(LATITUDE_ARRIVEE / 57.29577951) * " +
                "COS(LONGITUDE_ARRIVEE / 57.29577951 - LONGITUDE_DEPART / 57.29577951))) as DISTANCE " +
                "from " +
                "(select l.NUMERO_CHAUFFEUR, " +
                "regexp_substr(d1.COORDONNEES, '^[^,]+') as LATITUDE_DEPART, " +
                "trim(leading ',' FROM regexp_substr(d1.COORDONNEES, ',.*$')) AS LONGITUDE_DEPART, " +
                "regexp_substr(d2.COORDONNEES, '^[^,]+') as LATITUDE_ARRIVEE, " +
                "trim(leading ',' FROM regexp_substr(d2.COORDONNEES, ',.*$')) AS LONGITUDE_ARRIVEE " +
                "from LIVRAISONS l " +
                "inner join DEPOTS d1 on(l.NUMERO_DEPOT_DEPART = d1.NUMERO_DEPOT) " +
                "inner join DEPOTS d2 on(l.NUMERO_DEPOT_ARRIVE = d2.NUMERO_DEPOT) " +
                ")) " +
                "group by (NUMERO_CHAUFFEUR)";

但是java.sql.SQLException:ORA-01722:抛出了无效的数字。有人知道为什么吗?因为如果我直接使用sqlplus在sql中执行查询,它就可以正常工作。

使用sqlplus执行查询的结果:

NUMERO_CHAUFFEUR AVG(DISTANCE)
---------------- -------------
           1    507.064894
           2    703.326572
           5    846.966137
           4    511.914202
java sql oracle jdbc
1个回答
0
投票
尝试将字符串转换为数字,并且无法将字符串转换为数字时,发生ORA-01722错误。regexp_substr将返回字符串,并且您将其称为LATITUDE_DEPART,然后使用不正确的值进行数学运算。您应该先将其转换为数字。这可能会帮助您:

TO_NUMBER(regexp_substr(d1.COORDONNEES, '^[^,]')) LATITUDE_DEPART

对所有相同部分执行此操作。
© www.soinside.com 2019 - 2024. All rights reserved.