如何将 varchar2 类型转换为在 oracle 中浮动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24028782/
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
How to typecast varchar2 to float in oracle
提问by Aman Sehgal
ntwt FLOAT;
ntwt:=TO_FLOAT(substr(text,27,7));
Error(38,9): PLS-00201: identifier 'TO_FLOAT' must be declared
Please help
请帮忙
回答by Bob Jarvis - Reinstate Monica
Although there is a FLOAT type in Oracle, it's really just there for decoration purposes as there's no difference between FLOAT and NUMBER. In SYS.STANDARD FLOAT is defined as
虽然 Oracle 中有一个 FLOAT 类型,但它实际上只是为了装饰目的,因为 FLOAT 和 NUMBER 之间没有区别。在 SYS.STANDARD FLOAT 中定义为
subtype FLOAT is NUMBER;
Therefore, just use the TO_NUMBER
function to do your conversion, as in:
因此,只需使用该TO_NUMBER
函数进行转换,如下所示:
ntwt := TO_NUMBER(SUBSTR(TEXT, 27, 7));
Either that or define your own TO_FLOAT function:
要么定义你自己的 TO_FLOAT 函数:
CREATE OR REPLACE FUNCTION TO_FLOAT(s IN VARCHAR2) AS FLOAT IS
BEGIN
RETURN TO_NUMBER(s);
END TO_FLOAT;
Share and enjoy.
分享和享受。
回答by Guneli
There is not a TO_FLOAT function in ORACLE, you can use:
ORACLE 中没有 TO_FLOAT 函数,可以使用:
TO_BINARY_FLOAT(substr(text,27,7))