What is the dual table in Oracle?

In the oracle database, Dual table is basically used to get value of pseudo-columns. It contains following properties: 
  • It is owned by the sys user
  • It is available for all the users
  • It contains only one column which name is dummy with datatype Varchar2(1) , This column can have maximum width of one character.

List of Pseudo-columns
Some of the pseudo-columns are given below – 
  • systimestamp
  • syssate
  • rowed
  • rownum
  • uis
  • user

In oracle, it is a rumor that Select statement can be used only with the data which is available in the database, but in real time it is not true. 
We can also use Select statement for the data which is never saved in database.

Example – Get the system date which is stored in BIOS of the computer, not in any database.
Select sysdate from dual;

Example – Perform the calculation between two or more numbers which are not stored in the database
Select 240*30 from dual;

Owner of the dual table
We can get the owner detail of the dual table by using following oracle command –
Select owner, table_name from dba_tables where table_name = ‘Dual’;

Structure
We can get the structure of the dual table dual by using following command –
Desc dual;

User defined 
You can also own your table which will behave like a dual table. Follow the below steps –

Step 1 – Create a custom table by using the below oracle command:
Create table User_Dual (dummy varchar2(1))

Step 2 – Insert the value into the table:
Insert into User_Dual values(‘A’)

Now you can run the same command as dual table:
Example – Select sysdate from dual;
                  Select 240*30 from dual;

It will produce the same result as the dual table.

I hope this will help on overview about Dual table in oracle database.

Post a Comment

2 Comments

  1. "You can also own your table which will behave like a dual table" You can use any table, just include a limit on how many rows are returned - Rownum=1 in Oracle.

    ReplyDelete
  2. how we are able to access the dual without prefixing the schema and what are the permissions granted for dual

    ReplyDelete