Hi All,
Here comes what is likely the final post of the year 2023!
While there have been previous discussions on this topic, I’d like to delve deeper into the specific enhancements and features related to the use of the DUAL table in Oracle 23c and little more about this sweet little object in Oracle databases …
The DUAL table has been a part of the Oracle Database for a very long time. It has been a fundamental component of Oracle’s SQL language for decades. The DUAL table in Oracle Database serves a specific purpose and is often used for various tasks. Its primary function is to provide a one-row, one-column table that can be used for evaluating expressions or performing certain types of queries. DUAL is a table automatically created by Oracle Database along with the data dictionary. DUAL is in the schema of the user SYS but is accessible by the name DUAL to all users. It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X.
Some of the very popular use cases of it are – When evaluating expressions (SELECT SYSDATE FROM DUAL), Providing Constants (SELECT 10 * 5 FROM DUAL), In PL/SQL blocks or scripts, the DUAL table can be used to store and retrieve scalar values, we often use the DUAL table during testing or debugging to check the result of an expression or function without the need for an actual table … I always remember it using as a quick way to check connectivity of the database etc. I mean while it seemingly mundane, the DUAL table is a small but significant component in the Oracle database ecosystem, serving a variety of purposes across different contexts.
One of the interesting performance tip related to DUAL tables that I remember is – Starting from Oracle Database 10g Release 1, when calculating an expression that excludes the DUMMY column in the DUAL table, logical I/O is not executed. This optimization is identified as FAST DUAL in the execution plan. However, if you explicitly SELECT the DUMMY column from DUAL, this optimization is bypassed, and logical I/O is performed.
A quick example :
SQL> explain plan for select * from dual; ---> Logical IO will be performed.
select * from table(dbms_xplan.display(format=>'basic'));
----------------------------------
| Id | Operation | Name |
----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | TABLE ACCESS FULL| DUAL |
----------------------------------
Yet, when choosing a standard expression from DUAL, the FAST DUAL row source is employed:
SQL> explain plan for select sysdate from dual; ---> No Logical IO will be performed.
select * from table(dbms_xplan.display(format=>'basic'));
---------------------------------
| Id | Operation | Name |
---------------------------------
| 0 | SELECT STATEMENT | |
| 1 | FAST DUAL | |
---------------------------------
Starting with Oracle 23c, there is no need to explicitly select expressions from the DUAL table; you can simply omit the FROM clause altogether. Lets do a quick demo.
---------------------------------
-- Prior 23c release
---------------------------------
SQL > select sysdate from dual
SYSDATE
---------
28-DEC-23
SQL > select sysdate;
ORA-00923 FROM keyword not found where expected
-- One more test
SQL> create sequence emp2;
Sequence Created
SQL> select emp2.nextval from dual;
NEXTVAL
---------
1
SQL> select emp2.nextval;
ORA-00923 FROM keyword not found where expected
---------------------------------
-- In Oracle 23c
---------------------------------
SQL > select sysdate;
SYSDATE
---------
28-DEC-23
SQL> create sequence emp2;
Sequence Created
SQL> select emp2.nextval from dual;
NEXTVAL
---------
1
SQL> select emp2.nextval;
NEXTVAL
---------
2
Hope It Helped
Prashant Dixit




