dbTalk Databases Forums  

Strange behavior of subquery

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Strange behavior of subquery in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hans Mayr
 
Posts: n/a

Default Strange behavior of subquery - 02-22-2008 , 09:45 AM






Hello,

I have a view V_BASE. Now I created a query with the following
structure:

WITH w1 AS ( SELECT ..... V_BASE ....)
SELECT * FROM w1

Everything works fine.

Now I changed to

WITH w1 AS ( SELECT ..... V_BASE ....),
w2 AS (SELECT ... w1 ...),
w3 AS (SELECT ... w1...)
SELECT * FROM w1
UNION ALL
SELECT * FROM w2 WHERE 1=0
UNION ALL
SELECT * FROM w3 WHERE 1=0

And suddenly I get a different result, one date column in w1 changed
its values by exactly one month. The "WHERE 1=0" is just to turn off
w2 and w3, I will it on again once that I fixed the error. Has anybody
any idea how or why w2 and w3 could influence the result of w1? I work
on Oracle 9. I checked the structure carefully using http://www.sqlinform.com/
to make sure that the problem is not due to a wrong bracket or
something like that. Or could w1, w2 and w3 even influence the results
of V_BASE?

Thanks and Best,

Hans

Reply With Quote
  #2  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-22-2008 , 11:46 AM






On Feb 22, 9:45*am, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
Hello,

I have a view V_BASE. Now I created a query with the following
structure:

WITH w1 AS ( SELECT ..... V_BASE ....)
SELECT * FROM w1

Everything works fine.

Now I changed to

WITH w1 AS ( SELECT ..... V_BASE ....),
* *w2 AS (SELECT ... w1 ...),
* *w3 AS (SELECT ... w1...)
SELECT * FROM w1
UNION ALL
SELECT * FROM w2 WHERE 1=0
UNION ALL
SELECT * FROM w3 WHERE 1=0

And suddenly I get a different result, one date column in w1 changed
its values by exactly one month. The "WHERE 1=0" is just to turn off
w2 and w3, I will it on again once that I fixed the error. Has anybody
any idea how or why w2 and w3 could influence the result of w1? I work
on Oracle 9. I checked the structure carefully usinghttp://www.sqlinform.com/
to make sure that the problem is not due to a wrong bracket or
something like that. Or could w1, w2 and w3 even influence the results
of V_BASE?

Thanks and Best,

Hans
Not knowing which release of Oracle you're using ascertaining the
nature of the problem and it's possible solution is guesswork, at
best. Even replicating the 'problem' is questionable.

Post your Oracle release (to at least 4 numbers) if you really want
assistance with this.


David Fitzjarrell


Reply With Quote
  #3  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-22-2008 , 11:46 AM



On Feb 22, 9:45*am, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
Hello,

I have a view V_BASE. Now I created a query with the following
structure:

WITH w1 AS ( SELECT ..... V_BASE ....)
SELECT * FROM w1

Everything works fine.

Now I changed to

WITH w1 AS ( SELECT ..... V_BASE ....),
* *w2 AS (SELECT ... w1 ...),
* *w3 AS (SELECT ... w1...)
SELECT * FROM w1
UNION ALL
SELECT * FROM w2 WHERE 1=0
UNION ALL
SELECT * FROM w3 WHERE 1=0

And suddenly I get a different result, one date column in w1 changed
its values by exactly one month. The "WHERE 1=0" is just to turn off
w2 and w3, I will it on again once that I fixed the error. Has anybody
any idea how or why w2 and w3 could influence the result of w1? I work
on Oracle 9. I checked the structure carefully usinghttp://www.sqlinform.com/
to make sure that the problem is not due to a wrong bracket or
something like that. Or could w1, w2 and w3 even influence the results
of V_BASE?

Thanks and Best,

Hans
Not knowing which release of Oracle you're using ascertaining the
nature of the problem and it's possible solution is guesswork, at
best. Even replicating the 'problem' is questionable.

Post your Oracle release (to at least 4 numbers) if you really want
assistance with this.


David Fitzjarrell


Reply With Quote
  #4  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-22-2008 , 11:46 AM



On Feb 22, 9:45*am, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
Hello,

I have a view V_BASE. Now I created a query with the following
structure:

WITH w1 AS ( SELECT ..... V_BASE ....)
SELECT * FROM w1

Everything works fine.

Now I changed to

WITH w1 AS ( SELECT ..... V_BASE ....),
* *w2 AS (SELECT ... w1 ...),
* *w3 AS (SELECT ... w1...)
SELECT * FROM w1
UNION ALL
SELECT * FROM w2 WHERE 1=0
UNION ALL
SELECT * FROM w3 WHERE 1=0

And suddenly I get a different result, one date column in w1 changed
its values by exactly one month. The "WHERE 1=0" is just to turn off
w2 and w3, I will it on again once that I fixed the error. Has anybody
any idea how or why w2 and w3 could influence the result of w1? I work
on Oracle 9. I checked the structure carefully usinghttp://www.sqlinform.com/
to make sure that the problem is not due to a wrong bracket or
something like that. Or could w1, w2 and w3 even influence the results
of V_BASE?

Thanks and Best,

Hans
Not knowing which release of Oracle you're using ascertaining the
nature of the problem and it's possible solution is guesswork, at
best. Even replicating the 'problem' is questionable.

Post your Oracle release (to at least 4 numbers) if you really want
assistance with this.


David Fitzjarrell


Reply With Quote
  #5  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-22-2008 , 11:46 AM



On Feb 22, 9:45*am, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
Hello,

I have a view V_BASE. Now I created a query with the following
structure:

WITH w1 AS ( SELECT ..... V_BASE ....)
SELECT * FROM w1

Everything works fine.

Now I changed to

WITH w1 AS ( SELECT ..... V_BASE ....),
* *w2 AS (SELECT ... w1 ...),
* *w3 AS (SELECT ... w1...)
SELECT * FROM w1
UNION ALL
SELECT * FROM w2 WHERE 1=0
UNION ALL
SELECT * FROM w3 WHERE 1=0

And suddenly I get a different result, one date column in w1 changed
its values by exactly one month. The "WHERE 1=0" is just to turn off
w2 and w3, I will it on again once that I fixed the error. Has anybody
any idea how or why w2 and w3 could influence the result of w1? I work
on Oracle 9. I checked the structure carefully usinghttp://www.sqlinform.com/
to make sure that the problem is not due to a wrong bracket or
something like that. Or could w1, w2 and w3 even influence the results
of V_BASE?

Thanks and Best,

Hans
Not knowing which release of Oracle you're using ascertaining the
nature of the problem and it's possible solution is guesswork, at
best. Even replicating the 'problem' is questionable.

Post your Oracle release (to at least 4 numbers) if you really want
assistance with this.


David Fitzjarrell


Reply With Quote
  #6  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-25-2008 , 02:50 AM



Hello,

Thanks for your reply. Actually I was wrong, I do not work on Oracle
9. Here is the entry of v$version:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit
Production

I hope that you or someone else will be able to help me with this
mystery.

Best,

Hans

Reply With Quote
  #7  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-25-2008 , 02:50 AM



Hello,

Thanks for your reply. Actually I was wrong, I do not work on Oracle
9. Here is the entry of v$version:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit
Production

I hope that you or someone else will be able to help me with this
mystery.

Best,

Hans

Reply With Quote
  #8  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-25-2008 , 02:50 AM



Hello,

Thanks for your reply. Actually I was wrong, I do not work on Oracle
9. Here is the entry of v$version:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit
Production

I hope that you or someone else will be able to help me with this
mystery.

Best,

Hans

Reply With Quote
  #9  
Old   
Hans Mayr
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-25-2008 , 02:50 AM



Hello,

Thanks for your reply. Actually I was wrong, I do not work on Oracle
9. Here is the entry of v$version:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit
Production

I hope that you or someone else will be able to help me with this
mystery.

Best,

Hans

Reply With Quote
  #10  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Strange behavior of subquery - 02-25-2008 , 07:40 AM



On Feb 25, 2:50*am, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote:
Quote:
Hello,

Thanks for your reply. Actually I was wrong, I do not work on Oracle
9. Here is the entry of v$version:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit
Production

I hope that you or someone else will be able to help me with this
mystery.

Best,

Hans
And I'm not seeing any such behaviour on 10.2.0.3:

SQL> create or replace view v_base
2 as select * from user_objects;

View created.

SQL>
SQL> with w1 as (
2 select object_name, created, last_ddl_time, timestamp
3 from v_base
4 )
5 select * from w1;

OBJECT_NAME CREATED LAST_DDL_ TIMESTAMP
---------------- --------- --------- -------------------
CTRTEST 15-FEB-08 15-FEB-08 2008-02-15:14:29:38
HIYABABE 15-FEB-08 15-FEB-08 2008-02-15:14:43:10
TABLE2 20-FEB-08 20-FEB-08 2008-02-20:14:43:14
ABC 13-FEB-08 13-FEB-08 2008-02-13:08:19:23
ABC_IND 13-FEB-08 13-FEB-08 2008-02-13:08:20:18
ARTICLE 24-FEB-08 24-FEB-08 2008-02-24:16:12:31
EMP 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
DEPT 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
BONUS 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
SALGRADE 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
DUMMY 12-FEB-08 12-FEB-08 2008-02-12:08:10:13

OBJECT_NAME CREATED LAST_DDL_ TIMESTAMP
---------------- --------- --------- -------------------
LIGNECOMMANDE 24-FEB-08 24-FEB-08 2008-02-24:16:12:31
V_BASE 25-FEB-08 25-FEB-08 2008-02-25:07:29:20
T 19-FEB-08 19-FEB-08 2008-02-19:15:59:21
EXCEP_TAB 21-FEB-08 21-FEB-08 2008-02-21:09:27:56
TAB1 21-FEB-08 21-FEB-08 2008-02-21:09:27:56
TAB2 21-FEB-08 21-FEB-08 2008-02-21:09:27:56

17 rows selected.

SQL>
SQL> with w1 as (
2 select object_name, created, last_ddl_time, timestamp
3 from v_base
4 ),
5 w2 as (
6 select object_name, created, last_ddl_time, timestamp
7 from w1
8 ),
9 w3 as (
10 select object_name, created, last_ddl_time, timestamp
11 from w1
12 )
13 select * from w1
14 union all
15 select * from w2 where 0=1
16 union all
17 select * from w3 where 0=1;

OBJECT_NAME CREATED LAST_DDL_ TIMESTAMP
---------------- --------- --------- -------------------
CTRTEST 15-FEB-08 15-FEB-08 2008-02-15:14:29:38
HIYABABE 15-FEB-08 15-FEB-08 2008-02-15:14:43:10
TABLE2 20-FEB-08 20-FEB-08 2008-02-20:14:43:14
ABC 13-FEB-08 13-FEB-08 2008-02-13:08:19:23
ABC_IND 13-FEB-08 13-FEB-08 2008-02-13:08:20:18
ARTICLE 24-FEB-08 24-FEB-08 2008-02-24:16:12:31
EMP 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
DEPT 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
BONUS 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
SALGRADE 12-FEB-08 12-FEB-08 2008-02-12:08:10:12
DUMMY 12-FEB-08 12-FEB-08 2008-02-12:08:10:13

OBJECT_NAME CREATED LAST_DDL_ TIMESTAMP
---------------- --------- --------- -------------------
LIGNECOMMANDE 24-FEB-08 24-FEB-08 2008-02-24:16:12:31
V_BASE 25-FEB-08 25-FEB-08 2008-02-25:07:29:20
T 19-FEB-08 19-FEB-08 2008-02-19:15:59:21
EXCEP_TAB 21-FEB-08 21-FEB-08 2008-02-21:09:27:56
TAB1 21-FEB-08 21-FEB-08 2008-02-21:09:27:56
TAB2 21-FEB-08 21-FEB-08 2008-02-21:09:27:56

17 rows selected.

SQL>

Please post the results you're seeing so we can understand this
problem.


David Fitzjarrell


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.