Tuesday, June 14, 2022

Oracle SQL Float Data Type

 

1.    The FLOAT data type is a subtype of NUMBER.

2.     It can be specified with or without precision, which has the same definition it has for NUMBER and can range from 1 to 126.

3.    Scale cannot be specified but is interpreted from the data.

4.    Each FLOAT value requires from 1 to 22 bytes.

To convert from binary to decimal precision, multiply n by 0.30103. To convert from decimal to binary precision, multiply the decimal precision by 3.32193. The maximum of 126 digits of binary precision is roughly equivalent to 38 digits of decimal precision.

The difference between NUMBER and FLOAT is best illustrated by example. In the following example the same values are inserted into NUMBER and FLOAT columns:

Example:

CREATE TABLE test (col1 NUMBER(5,2), col2 FLOAT(5));

INSERT INTO test VALUES (1.23, 1.23);

INSERT INTO test VALUES (7.89, 7.89);

INSERT INTO test VALUES (12.79, 12.79);

INSERT INTO test VALUES (123.45, 123.45);

 SELECT * FROM test;

 

      COL1       COL2

---------- ----------

      1.23        1.2

      7.89        7.9

     12.79         13

    123.45        120

No comments:

Post a Comment