Aman Sehgal
Aman Sehgal

Reputation: 11

How to typecast varchar2 to float in oracle

ntwt          FLOAT;

ntwt:=TO_FLOAT(substr(text,27,7));


Error(38,9): PLS-00201: identifier 'TO_FLOAT' must be declared

Please help

Upvotes: 1

Views: 31321

Answers (2)

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

subtype FLOAT is NUMBER;

Therefore, just use the TO_NUMBER function to do your conversion, as in:

ntwt := TO_NUMBER(SUBSTR(TEXT, 27, 7));

Either that or define your own TO_FLOAT function:

CREATE OR REPLACE FUNCTION TO_FLOAT(s IN VARCHAR2) AS FLOAT IS
BEGIN
  RETURN TO_NUMBER(s);
END TO_FLOAT;

Share and enjoy.

Upvotes: 4

Guneli
Guneli

Reputation: 1721

There is not a TO_FLOAT function in ORACLE, you can use:

TO_BINARY_FLOAT(substr(text,27,7)) 

Upvotes: -1

Related Questions