3

我收到以下错误“发生了无效的浮点运算”。当我运行此查询时:

SELECT PolID, LocID, Address, City, StateCode, OrigGeoLat, OrigGeoLong, NewGeoLat, NewGeoLong, 
acos(sin(radians(OrigGeoLat)) * sin(radians(NewGeoLat)) +
        cos(radians(OrigGeoLat)) * cos(radians(NewGeoLat)) *
        cos(radians(OrigGeoLong - NewGeoLong))) * 6372.8  as Distance
FROM zzGeoDataTMP

所有 *geoLat 和 *geoLong 数据都定义为 numeric(18,10)。当我运行查询时,我开始取回数据,然后在特定的数据行上出现错误。例如,以下行仅在调用 ACOS 函数时才引发上述异常:

OrigGeoLat|OrigGeoLong|NewGeoLat|NewGeoLong
---------------------------------------------
32.9364620|-80.0411000|32.9364620|-80.0411000

非常感谢您提供任何可以提供帮助的见解!

4

1 回答 1

9

您的计算正在累积一些小错误,这意味着计算值(传递给ACOS略高于1。尝试用ROUND调用包装它:

acos(ROUND(sin(radians(OrigGeoLat)) * sin(radians(NewGeoLat)) +
    cos(radians(OrigGeoLat)) * cos(radians(NewGeoLat)) *
    cos(radians(OrigGeoLong - NewGeoLong)),15)
    )

我们保留小数点后 15 位的准确性。

于 2012-07-09T14:50:52.190 回答