DUAL table
Encyclopedia
The DUAL table is a special one-row table
Table (database)
In relational databases and flat file databases, a table is a set of data elements that is organized using a model of vertical columns and horizontal rows. A table has a specified number of columns, but can have any number of rows...

 present by default in all Oracle
Oracle database
The Oracle Database is an object-relational database management system produced and marketed by Oracle Corporation....

 database
Relational database
A relational database is a database that conforms to relational model theory. The software used in a relational database is called a relational database management system . Colloquial use of the term "relational database" may refer to the RDBMS software, or the relational database itself...

 installations. It is suitable for use in selecting a pseudocolumn
Pseudocolumn
A Pseudocolumn is a "column" that yields a value when selected, but which is not an actual column of the table. An example is RowID or SysDate. It is often used in combination with the DUAL table...

 such as SYSDATE or USER.
The table has a single VARCHAR2(1) column called DUMMY that has a value of 'X'.

Example use

Oracle's SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

 syntax requires the FROM
From (SQL)
The SQL From clause is the source of a rowset to be operated upon in a Data Manipulation Language statement. From clauses are very common, and will provide the rowset to be exposed through a Select statement, the source of values in an Update statement, and the target rows to be deleted in a...

 clause but some queries don't require any tables - DUAL can be readily used in these cases.


SELECT 1+1
FROM DUAL;

SELECT SYSDATE
FROM DUAL;

SELECT USER
FROM DUAL;

History

The DUAL table was created by Charles Weiss
Charles Weiss
Charles Weiss is an American software designer and one of the first employees of Oracle Corporation, having joined in 1982 when there were only 25 employees....

 of Oracle corporation
Oracle Corporation
Oracle Corporation is an American multinational computer technology corporation that specializes in developing and marketing hardware systems and enterprise software products – particularly database management systems...

 to provide a table for joining in internal views
View (database)
In database theory, a view consists of a stored query accessible as a virtual table in a relational database or a set of documents in a document-oriented database composed of the result set of a query or map and reduce functions...

:


I created the DUAL table as an underlying object in the Oracle Data Dictionary. It was never meant to be seen itself, but instead used inside a view that was expected to be queried. The idea was that you could do a JOIN to the DUAL table and create two rows in the result for every one row in your table. Then, by using GROUP BY, the resulting join could be summarized to show the amount of storage for the DATA extent and for the INDEX extent(s). The name, DUAL, seemed apt for the process of creating a pair of rows from just one.


The original DUAL table had two rows in it (hence its name), but subsequently it only had one row.

Optimization

DUAL was originally a table and the database engine would perform disk IO on the table when selecting from DUAL. This disk IO was usually logical IO (not involving physical disk access) as the disk blocks were usually already cached in memory. This resulted in a large amount of logical IO against the DUAL table.

Later versions of the Oracle database have been optimized and the database no longer performs physical or logical IO on the DUAL table even though the DUAL table still actually exists.

In other database systems

MySQL
MySQL
MySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...

allows DUAL to be specified as a table in queries that do not need data from any tables.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK