FLOAT
Example
Section titled “Example”CREATE TABLE TestTable ( exampleField FLOAT(7,2));INSERT INTO TestTable (exampleField)VALUES (12345.67);Output
Section titled “Output”Query OK, 1 row affected (0.01 sec)Explanation
Section titled “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
Section titled “Example”CREATE TEMPORARY TABLE temporary_table (floating_no FLOAT);INSERT INTO temporary_table values (1.23);SELECT * FROM temporary_table;Output
Section titled “Output” floating_no------------- 1.23Explanation
Section titled “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
Section titled “Example”DECLARE @float_num FLOAT;SET @float_num = 123.456;
SELECT @float_num AS FloatNumber;Output
Section titled “Output”FloatNumber-----------123.456Explanation
Section titled “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
Section titled “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
Section titled “Output”product_id | product_price------------|--------------1 | 24.992 | 22.573 | 45.33Explanation
Section titled “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
Section titled “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
Section titled “Output”Product_ID | Price-----------|------1 | 9.992 | 19.993 | 29.99Explanation
Section titled “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.