FLOAT4
FLOAT4 in SQL refers to a data type that is used to store floating-point numbers. It allows for single precision floating-point numbers, which means they require 4 bytes of storage and can handle up to 6 digits of precision. It is commonly used when the exact precision of a number is not required.
Example
CREATE TABLE items ( id SERIAL PRIMARY KEY, product VARCHAR(100), weight FLOAT4);
INSERT INTO items (product, weight) VALUES ('Apple', 0.12), ('Banana', 0.15);
SELECT * FROM items;Output
id | product | weight----|---------|-------- 1 | Apple | 0.12 2 | Banana | 0.15Explanation
This sample SQL code creates a table named items with three columns: id, product and weight. The weight column uses the FLOAT4 data type to store floating-point numbers. Two rows are inserted into the items table, and then all records from the table are selected with a SELECT * FROM items command. The output shows the results of this select query.
Example
DECLARE num FLOAT4;BEGIN num := 12.3456; DBMS_OUTPUT.PUT_LINE('The value of num is ' || num);END;Output
The value of num is 12.3456Explanation
In the provided example, FLOAT4 data type in Oracle SQL is used to declare a variable num. The variable is then assigned the value of 12.3456. The DBMS_OUTPUT.PUT_LINE function is then used to output the value of num, resulting in the displayed output. The FLOAT4 data type supports a precision of floating point numbers up to 4 bytes.