DOUBLE
Example
Section titled “Example”CREATE TABLE Employee ( ID int, Salary DOUBLE(8,2));
INSERT INTO Employee(ID, Salary)VALUES (1, 3500.75), (2, 4500.50);
SELECT * FROM Employee;Output
Section titled “Output”+------+---------+| ID | Salary |+------+---------+| 1 | 3500.75 || 2 | 4500.50 |+------+---------+Explanation
Section titled “Explanation”In this example, a table named Employee is created with two columns: ID (an integer) and Salary (a DOUBLE). A DOUBLE in MySQL is a floating-point number that allows for decimal points. The notation DOUBLE(8,2) specifies that the Salary numbers have a total of 8 digits, of which 2 are after the decimal point. The INSERT INTO statement is used to add two rows of data into the Employee table. Running SELECT * FROM Employee then retrieves all records from the table.
Example
Section titled “Example”DECLARE @Value DOUBLE;SET @Value = 10.12345;SELECT @Value AS 'Double Value';Output
Section titled “Output”Double Value-----------10.12345Explanation
Section titled “Explanation”The provided SQL Server script declares a variable @Value of DOUBLE datatype and assigns it the value 10.12345. The SELECT statement is used to return this value.
Example
Section titled “Example”CREATE TABLE Employee ( ID NUMBER, Salary DOUBLE PRECISION);
INSERT INTO Employee (ID, Salary) VALUES (1, 75000.50), (2, 60000.80);
SELECT * FROM Employee;Output
Section titled “Output”ID | Salary1 | 75000.502 | 60000.80Explanation
Section titled “Explanation”The DOUBLE PRECISION data type is a floating point numeral data type that holds 15 digits of precision. It is capable of storing numbers that are substantially larger or smaller than those that can be stored in an NUMBER data type. When retrieving data from Employee table, it correctly displays the decimal precision in salaries.
Example
Section titled “Example”CREATE TABLE employees ( id INTEGER PRIMARY KEY, first_name TEXT, last_name TEXT, salary DOUBLE);
INSERT INTO employees (first_name, last_name, salary)VALUES ('John', 'Doe', 50000.75);Output
Section titled “Output”To verify the data, use the following SELECT statement.
SELECT * FROM employees;Output:
id: 1first_name: Johnlast_name: Doesalary: 50000.75Explanation
Section titled “Explanation”In the example above, a new SQLite table called ‘employees’ is created with four columns: ‘id’ (an integer that serves as a primary key), ‘first_name’ (a text string), ‘last_name’ (a text string), and ‘salary’ (a double precision number).
After the table is created, data is inserted into it. The ‘salary’ field is filled with a double value, which is a number that can include fractional parts, as shown by the value 50000.75.
The SELECT statement is then used to retrieve the data from the table, confirming that the ‘salary’ value was stored accurately.