Convert string to decimal in oracle

0

I try to convert a decimal number contained within a string to a decimal and I get the following error:

Oracle Database

  

ORA-01722: invalid number   01722. 00000 - "invalid number"   * Cause: The specified number was invalid.   * Action: Specify a valid number.

SQL Code:

TO_NUMBER('5.0') AS numero

CAST('5.0' AS NUMBER) AS numero
    
asked by Andres Felipe Polo 03.02.2018 в 05:34
source

2 answers

0

If this is the number in question: 01722. 00000 , you can recognize it as invalid because there is a space between the point and the zero that continues. Before converting, use a REPLACE function where you replace the space with a blank character. Example:

CAST(REPLACTE(miNumero, ' ', '') as NUMBER)
    
answered by 03.02.2018 в 13:59
0

Andres

Your problem is that you pass the string of the number with period '.' and not with comma ',', your conversion functions are ok, but you must replace the comma point before.

SELECT 
TO_NUMBER (
REPLACE('5.33','.',',')
) AS NUMERO1,

CAST(
REPLACE('5.33','.',',')
AS NUMBER) 
AS NUMERO2
    
answered by 24.01.2019 в 13:07