DUAL table in SQL
The DUAL table is a special one-row, one-column table in SQL that is commonly used in Oracle databases. It is used to perform calculations, evaluate expressions, and return a single result value. Here are some details about the DUAL table:
-
Structure: The DUAL table has only one column named DUMMY and one row with a single value of 'X'.
-
Purpose: The DUAL table is used to perform calculations or evaluate expressions that do not require data from any table. It is often used in SELECT statements to return a single result value.
-
Syntax: The syntax for using the DUAL table in a SELECT statement is as follows:
SELECT expression FROM DUAL;
For example, to return the current date and time, you can use the following query:
SELECT SYSDATE FROM DUAL;
- Usage: The DUAL table can be used in various ways, such as:
a. To perform arithmetic calculations:
SELECT 10 + 5 FROM DUAL;
b. To concatenate strings:
SELECT 'Hello' || ' ' || 'World' FROM DUAL;
c. To evaluate expressions:
SELECT (10 * 5) / 2 FROM DUAL;
d. To return a constant value:
SELECT 'ABC' FROM DUAL;
e. To return the result of a function:
SELECT UPPER('hello') FROM DUAL;
f. To generate a sequence of numbers:
SELECT LEVEL FROM DUAL CONNECT BY LEVEL <= 10;
This query will return a sequence of numbers from 1 to 10.
Overall, the DUAL table is a useful tool in SQL for performing calculations and evaluating expressions that do not require data from any table.