DUAL table
Example use
History
Charles Weiss explains why he created DUAL:
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.{{cite news|title=More About Oracle's History |url=http://www.oracle.com/technology/oramag/oracle/02-jan/o12sendmail.html |accessdate=4 September 2013 |newspaper=Oracle Magazine |date=January–February 2002 |url-status=dead |archiveurl=https://web.archive.org/web/20041205061859/http://www.oracle.com/technology/oramag/oracle/02-jan/o12sendmail.html |archivedate=December 5, 2004 }}
Optimization
Beginning with 10g Release 1, Oracle no longer performs physical or logical I/O on the DUAL table, though the table still exists.[https://docs.oracle.com/cd/E11882_01/server.112/e41084/queries009.htm#SQLRF20036 Oracle Database SQL Language Reference 11g Release 2 (11.2), Selecting from the DUAL Table]
DUAL is readily available for all authorized users in a SQL database.
In other database systems
Several other databases (including Microsoft SQL Server, MySQL, PostgreSQL, SQLite, and Teradata) enable one to omit the FROM clause entirely if no table is needed. This avoids the need for any dummy table.
- ClickHouse has a one-row system table system.one with a single column named "dummy" of type UInt8 and value 0. This table is implicitly used when no table is specified in the SELECT query.
- Firebird has a one-row system table RDB$DATABASE that is used in the same way as Oracle's DUAL, although it also has a meaning of its own.
- IBM Db2 has a view that resolves DUAL when using Oracle Compatibility.[http://publib.boulder.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.apdv.porting.doc/doc/r0052874.html DB2 10.1 InfoCenter :: DB2 Version 10.1 for Linux, UNIX, and Windows - DUAL table] It also has a table called sysibm.sysdummy1 that has similar properties to the Oracle DUAL one.
- Informix: Informix version 11.50 and later has a table named {{code|2=sql|sysmaster:"informix".sysdual}} with the same functionality but a more verbose name.[https://www.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.adref.doc/ids_adr_0225.htm Informix 12.10 InfoCenter :: Administrator's Reference :: The sysmaster database :: The System-Monitoring Interface Tables :: sysdual] You can use {{code|2=sql|CREATE PUBLIC SYNONYM dual FOR sysmaster:"informix".sysdual}} to create a name {{code|2=sql|dual}} in the current database with the same functionality.
- Microsoft Access: A table named DUAL may be created and the single-row constraint enforced via ADO ([https://stackoverflow.com/a/7933927/154439 Table-less UNION query in MS Access])
- Microsoft SQL Server: SQL Server does not require a dummy table. Queries like 'select 1 + 1' can be run without a "from" clause/table name.[https://stackoverflow.com/questions/28371342/what-is-the-oracle-equivalent-of-dual-table-in-sqlserver What is the Oracle equivalent of “Dual” table in SqlServer?]
- MySQL allows DUAL to be specified as a table in queries that do not need data from any tables.{{Cite web |url=http://dev.mysql.com/doc/refman/5.0/en/select.html |title=MySQL :: MySQL 5.0 Reference Manual :: 13.2.8 SELECT Syntax |access-date=2009-03-14 |archive-url=https://web.archive.org/web/20120103180754/http://dev.mysql.com/doc/refman/5.0/en/select.html |archive-date=2012-01-03 |url-status=dead }} It is suitable for use in selecting a result function such as [http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_sysdate SYSDATE()] or [http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_user USER()], although it is not essential.
- PostgreSQL: A DUAL-view can be added to ease porting from Oracle.[http://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion#The_Dual_Table PostgreSQL :: PostgreSQL Wiki :: Oracle to Postgres Conversion]
- Snowflake: DUAL is supported, but not explicitly documented. It [https://docs.snowflake.net/manuals/user-guide/querying-sequences.html#sequences-as-expressions appears in sample SQL for other operations] in the documentation.
- SQLite: A VIEW named "dual" that works the same as the Oracle "dual" table can be created as follows: {{code|2=sql|CREATE VIEW dual AS SELECT 'x' AS dummy;}}
- SAP HANA has a table called DUMMY that works the same as the Oracle "dual" table.
- Teradata database does not require a dummy table. Queries like 'select 1 + 1' can be run without a "from" clause/table name.
- Vertica has support for a DUAL table in their official documentation.{{Cite web |title=DUAL |url=https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/SystemTables/CATALOG/DUAL.htm |access-date=2022-03-10 |website=www.vertica.com}}