A dual table is a dummy table in Oracle. It comes with the database installation. We will talk about selecting something from the dual table in this post.

This page contains (Skip to topic)..

## What is the DUAL table?

- The special table comes preinstalled in the Oracle database
- It has one row and one column in it.
- The datatype of its column is varchar2(1).
- The DUAL table is in the SYS user.
- The DUAL table is accessible to all the users in the database.
- It has a value X in it.
- It is useful to compute a constant expression with the select statement. As dual has only one row, it returns a value.
- In addition to this, you can also select a constant, pseudo column, or expression from any table, but the value will be returned as many times as there are rows in the table.

You can read more on SQL Dual to see each of the points in detail. As this post is primarily for selecting from dual, we will stick to it.

### Use SELECT DUAL to compute a constant expression

--Example #1 ---------------------------------- SELECT sysdate FROM DUAL; --Result SYSDATE -------- 08-09-18 --Example #2 ----------------------------------- SELECT length('Rozalin') FROM DUAL; --Result LENGTH('ROZALIN') ----------------- 7

Please note that, both the queries returned a single row as the dual table has only one row. The sysdate, length functions returns the current date and length of a string literal respectively.

### Use SELECT DUAL with constants

We can select a constant from the dual table. It will give the same value as the result. Here is an example showing the same.

--Example #1 ------------------------------ SELECT 'Subhashree' FROM DUAL; --Result 'SUBHASHRE ---------- Subhashree --Example #2 ------------------------------ SELECT 12 FROM dual; --Result 12 ------------------------------ 12

### Use SELECT DUAL with pseudo column

A pseudo column is a value given by the Oracle used like Oracle database columns. However, it does not exist in the database.

Some of the pseudo-columns SQL, PLSQL understand are, SYSDATE, SYSTIMESTAMP, ROWID, ROWNUM, UID, USER, LEVEL, CURRVAL, NEXTVAL, ORA_ROWSCN, etc.

SELECT ROWNUM,employees.* FROM employees;

### Use SELECT DUAL to compute the expression

We can use dual to calculate expression.

SELECT 12 / 5 + 3 FROM dual; --Result ------------------------------------- 12/5+3 ---------- 5.4

We can also use SQL SELECT query to compute expressions as new columns. We will talk on how we can calculate expression in the select query itself in the next post.

## Your turn now. Please share your questions or feedback. :-)