vb.net Oracle:将字符串转换为双精度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20614813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:09:35  来源:igfitidea点击:

Oracle: Convert string to double

sqlvb.netoracle

提问by bbesase

This is my query for a database pull:

这是我对数据库拉取的查询:

SELECT DISTINCT
TEMPLATE_GROUP_PROPERTIES.PROPERTYTYPE,
PROPERTY.PROPERTYVAL

FROM
TEMPLATE_GROUP_PROPERTIES

LEFT OUTER JOIN PROPERTY_DATA
ON (TEMPLATE_GROUP_PROPERTIES.PROPERTYGROUPID = PROPERTYDATA.PROPERTYGROUPID)

WHERE
PROPERTY.PROPERTYVAL = :propValue

Whoever created the database made the Property.Propertyvalcolumn a column defined as a string when it is represented as scientific notation numbers (4.0E-3, 2.0E2, etc). I need to convert either the string to a double or the double to a string whatever way would work and I don't know how. I have tried messing around with the TO_NUMBER()function and have found nothing of help so far.

创建数据库的人Property.Propertyval将该列定义为字符串,当它用科学记数法表示时(4.0E-3、2.0E2 等)。我需要以任何可行的方式将字符串转换为双精度或双精度转换为字符串,但我不知道如何操作。我试过弄乱这个TO_NUMBER()函数,到目前为止没有找到任何帮助。

回答by Gordon Linoff

If you really know that the string is a valid number, then use cast():

如果您确实知道该字符串是有效数字,请使用cast()

WHERE cast(property.propertyval as float) = :propValue

Some cautions.

一些警告。

First, the use of the function will prevent the query from using an index on propertyval. You can always create a functional index if you need an index.

首先,使用该函数会阻止查询使用 上的索引propertyval。如果需要索引,您始终可以创建功能索引。

Second, comparisons of floating point values can be problematic when the values are very close. You might consider:

其次,当值非常接近时,浮点值的比较可能会出现问题。你可能会考虑:

WHERE abs(cast(property.propertyval as float) - :propValue) < 0.001

Or some other threshold value.

或者其他一些阈值。