Insert into DUAL

On the Oracle-l mailing list, Jared Still posted a message about a little experiment he did which concluded that Oracle (10gR1) always makes sure that DUAL returns one and only one row even if it contains more than one row.

I have repeated the experiment on my Oracle 10g XE database (Important: Do not do this dangerous stuff on your production database. Never insert/delete/update DUAL):

SQL*Plus: Release 10.2.0.1.0 - Beta on Tue Nov 8 19:21:20 2005

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> connect sys as sysdba
Enter password:
Connected.
SQL> insert into dual values('A');

1 row created.

SQL> insert into dual values('B');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from dual;

D
-
X

Rows A and B are not returned, why?

SQL> disconnect
Disconnected from Oracle Database 10g Express Edition 
Release 10.2.0.1.0 - Beta
SQL> connect hr/hr
Connected.
SQL> select * from dual;

D
-
X

SQL> create table hr_dual as select * from dual;

Table created.

SQL> select * from hr_dual;

D
-
X
A
B

Now, A and B are returned if I do not select from DUAL directly.

Now, I will delete rows A and B from DUAL:

SQL> disconn
Disconnected from Oracle Database 10g Express Edition 
Release 10.2.0.1.0 - Beta
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> delete dual where dummy = 'A';

1 row deleted.

SQL> delete dual where dummy = 'B';

1 row deleted.

SQL> commit;

Commit complete.

I will make sure that the rows are deleted from DUAL:

SQL> disconn
Disconnected from Oracle Database 10g Express Edition 
Release 10.2.0.1.0 - Beta
SQL> connect hr/hr
Connected.
SQL> select * from dual;

D
-
X

SQL> drop table hr_dual;

Table dropped.

SQL> create table hr_dual as select * from dual;

Table created.

SQL> select * from hr_dual;

D
-
X

The rows are deleted from DUAL. Interesting indeed.


Possibly related:


Tagged , | Post a Comment