Let's consider the contents of the famous dual table:
Now let's try to get multiple rows returned form dual:
So there's still one row, whichs results in a rownum of 1. Now let's ask the max of rownum:
Kinda strange isn't it? Now let's try to get these 5 rows:
Another strange feature is that in TOAD
returns 5 rows (and in SQL*Plus only one as you can see above).
Does this kind of behaviour also occurs on other tables/views?
In my application I've got one materialized view, so a select from all_mviews returns one row (just like dual):
So the one row from dual behaves different than the one row from all_mviews....
So what you see is what you get, but what you get is not what you have!
SQL>select * from dual;
D
-
X
SQL>select rownum from dual;
ROWNUM
----------
1
Now let's try to get multiple rows returned form dual:
SQL>select rownum from dual connect by rownum < = 5;
ROWNUM
----------
1
So there's still one row, whichs results in a rownum of 1. Now let's ask the max of rownum:
SQL>select max(rownum) from dual connect by rownum < = 5;
MAX(ROWNUM)
-----------
5
Kinda strange isn't it? Now let's try to get these 5 rows:
SQL>select * from (select rownum from dual connect by rownum < = 5);
ROWNUM
----------
1
2
3
4
5
Another strange feature is that in TOAD
select rownum from dual connect by rownum < = 5
returns 5 rows (and in SQL*Plus only one as you can see above).
Does this kind of behaviour also occurs on other tables/views?
In my application I've got one materialized view, so a select from all_mviews returns one row (just like dual):
SQL>select count(*) from all_mviews;
COUNT(*)
----------
1
SQL>select rownum from all_mviews;
ROWNUM
----------
1
SQL>select rownum from all_mviews connect by rownum< =5;
ROWNUM
----------
1
2
3
4
5
SQL>select rownum from dual connect by rownum< =5;
ROWNUM
----------
1
So the one row from dual behaves different than the one row from all_mviews....
So what you see is what you get, but what you get is not what you have!
Comments
SQL*Plus: Release 10.2.0.2.0 - Production on Thu Apr 16 16:11:21 2009
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
SQL> select rownum from dual connect by rownum < = 5;
ROWNUM
----------
1
2
3
4
5
SQL>