FLOAT

FLOAT is a numerical data type in SQL. It is used to store floating-point numbers with varying precision, supporting large mathematical or scientific calculations where exact precision may not be crucial. The storage size of FLOAT can vary, but it generally allows a larger number of digits to the right of a decimal point compared to other numerical types. It is well suited for approximate values with a large range of positive or negative values.

Example

CREATE TABLE TestTable (
exampleField FLOAT(7,2)
);
INSERT INTO TestTable (exampleField)
VALUES (12345.67);

Output

Query OK, 1 row affected (0.01 sec)

Explanation

In the given example, a new table, TestTable, is created with one column, exampleField, of data type FLOAT(7,2). Then a data value 12345.67 is inserted into the column. The floating point type FLOAT(7,2) means that exampleField can store floating point numbers with up to 7 digits in total, of which 2 can be after the decimal point.

Example

CREATE TEMPORARY TABLE temporary_table (floating_no FLOAT);
INSERT INTO temporary_table values (1.23);
SELECT * FROM temporary_table;

Output

floating_no
-------------
1.23

Explanation

In the example, a temporary table named temporary_table is created with one column floating_no of type FLOAT. A row containing the value 1.23 is inserted into the table. The SELECT statement retrieves all entries from the table, producing the output 1.23. The FLOAT data type is used to store floating-point number data.

Example

DECLARE @float_num FLOAT;
SET @float_num = 123.456;
SELECT @float_num AS FloatNumber;

Output

FloatNumber
-----------
123.456

Explanation

In the example, a float variable @float_num is declared and initialized with the value 123.456. The SELECT statement is then used to return the value of @float_num, showing the ability of float data type to handle decimal point precision.

Example

CREATE TABLE product_table (
product_id INT,
product_price FLOAT
);
INSERT INTO product_table VALUES (1, 24.99);
INSERT INTO product_table VALUES (2, 22.57);
INSERT INTO product_table VALUES (3, 45.33);
SELECT * FROM product_table;

Output

product_id | product_price
------------|--------------
1 | 24.99
2 | 22.57
3 | 45.33

Explanation

The example demonstrates the use of the FLOAT type in Oracle SQL. A new table named product_table is created with two columns. The product_price column is defined with FLOAT data type to store floating point numbers. Three products with different prices are inserted into the table. The SELECT statement retrieves all records from the table, confirming that the product_price values have been stored as floating point numbers successfully.

Example

CREATE TABLE Sales (
Product_ID INTEGER PRIMARY KEY,
Price FLOAT
);
INSERT INTO Sales (Product_ID, Price)
VALUES (1, 9.99), (2, 19.99), (3, 29.99);
SELECT * FROM Sales;

Output

Product_ID | Price
-----------|------
1 | 9.99
2 | 19.99
3 | 29.99

Explanation

A FLOAT in SQL is used to store floating-point numbers. In this example, a table Sales is created with two columns - Product_ID (an integer which is the primary key), and Price (a floating-point number). Three rows of data are inserted into the table, each with a product ID and a price. The SELECT * FROM Sales; statement is used to retrieve all the data from the table. The output confirms that the floating-point numbers have been correctly inserted and are accurately displayed.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.