How not to convert an exponential number to decimal?

Asked

Viewed 265 times

0

Guys I’m having the following problem:

I created a function to put the thousand point(s) in the values you receive as parameter (VARCHAR2). This function takes integer values and values of type VARCHAR ('Some text'). When the value is not integer or is not greater than 999 returns exactly the amount that came in. The problem is that when it receives an exponential number the function converts to VARCHAR and ceases to be expressed in exponential. Ex:

SQL> SELECT pontoMilhar2(1E-2) nTratado FROM dual;

Returns ,01. What should return was 1E-2, because it’s no bigger than 999. Once you enter the function the value is already ,01.

CREATE OR REPLACE FUNCTION pontoMilhar2 (inValor IN VARCHAR2)
   RETURN VARCHAR2
IS
BEGIN
   IF isFloat (inValor) = 1
   THEN
      IF inValor > 999
      THEN
         RETURN pontoMilhar1(inValor);
      ELSE
         RETURN inValor;
      END IF;
   ELSE
      RETURN inValor;
   END IF;

   RETURN inValor;
END pontoMilhar2;

NOTE: I put this pointMilhar1 because from now on it works perfect.

Prgunta: Is there any input parameter that does not perform this conversion??

  • Publishes the pointMilhar1

  • One detail, the function will ALWAYS convert to varchar2, which is the data type of defined as parameter. One suggestion to allow sending a number or varchar, is to use the function Overload (basically, having 2 functions with the same name, but receiving different data types) with Packages. Even though I’m not much of a fan, I think it’s a valid situation for you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.