473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Strange SQL behaviour when using query short-cuts

I am running a 9.0.1 database on a W2K server and have come across
some strange behaviour with a SQL query.
I have a query which runs in a PL/SQL cursor which has several PL/SQL
variables used to switch on and off certain rules. One idea I had was
to have two queries UNIONed together with a simple switch selecting
which half was to operate (I know it sounds like there are probably
better ways of doing this but I have my reasons).

To cut a long story short (too late, I hear you cry?), adding "AND
0=1" to a query will only *sometimes* be included in the rules. If you
will excuse the long post, below is a simplified example which can be
copied & pasted into SQL*Plus to demonstrate the issue.

Why does it behave this way, as I am sure it did not with oracle 8.0.5
(I used to use this approach to get really slow queries short-cut when
analysing execution paths)?

If you change the "0=1" to "ID=ID+1" it works as expected, but takes
longer (normally, short-cutting a query takes no time, which is why I
was not concerned about using a UNIONed query).

----------------------------

-- Same thing happens with non-temporary tables
create global temporary table play
(
id number(12) not null,
name varchar2(30) not null,
dob date
)
on commit delete rows;

INSERT INTO play
(id, NAME, dob)
VALUES (1, 'Bob', TO_DATE ('01-01-1971','dd-mm-yyyy'));

INSERT INTO play
(id, NAME, dob)
VALUES (1, 'Ben', TO_DATE ('02-03-1974','dd-mm-yyyy'));

-- A simple example - it works as expected
SELECT id, NAME, TO_CHAR (dob, 'DD-MON-YYYY HH24:MI:SS')
FROM play
WHERE id < 10
AND ('%e%' IS NULL OR LOWER(Name) LIKE LOWER('%e%'))
AND ('' IS NULL OR dob >= TO_DATE('', 'DD-MON-YYYY HH24:MI:SS'));
-- (Remember that '' is identical to NULL to oracle)

-- As above, but with "0=1" as the first part of the restrictions.
-- This also works as expected.
SELECT id, NAME, TO_CHAR (dob, 'DD-MON-YYYY HH24:MI:SS')
FROM play
WHERE 0=1
AND id < 10
AND ('%e%' IS NULL OR LOWER(Name) LIKE LOWER('%e%'))
AND ('' IS NULL OR dob >= TO_DATE('', 'DD-MON-YYYY HH24:MI:SS'));

-- As above, but with the "0=1" moved to the end of the restrictions.
-- In this case it does NOT work as expected.
SELECT id, NAME, TO_CHAR (dob, 'DD-MON-YYYY HH24:MI:SS')
FROM play
WHERE id < 10
AND ('%e%' IS NULL OR LOWER(Name) LIKE LOWER('%e%'))
AND ('' IS NULL OR dob >= TO_DATE('', 'DD-MON-YYYY HH24:MI:SS'))
AND 0=1;

----------------------------

Is this a bug? I think we should be told!

ETA
Jul 19 '05 #1
0 2677

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Mizrahi | last post by:
Hello, All! i admit that it's better to ask questions connected with atl/mfc classes in special newsgroups, but seems like people there are interested more in discussing stuff like MFC GUI than...
10
by: Mark Barinstein | last post by:
Hello. W2K, db2 v7, fp11. Given: create table pays ( acode integer not null, packno smallint not null, sum decimal(15, 2) not null
2
by: Mal | last post by:
Greetings. I have a perplexing problem....please help. I am having a problem with an insert query. (SQL below) When I run the query via code (executing the SQL string) it crashes Access and...
3
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP...
10
by: bear | last post by:
hi all, I have a program whose speed is so strange to me. It is maily used to calculate a output image so from four images s0,s1,s2,s3 where so=(s0-s2)^2+ (s1-s3)^2. I compile it with gcc (no...
31
by: gamehack | last post by:
Hi all, I've been testing out a small function and surprisingly it does not work okay. Here's the full code listing: #include "stdlib.h" #include "stdio.h" char* escaped_byte_cstr_ref(char...
14
by: Bo Yang | last post by:
Following is my code: include <iostream> class Test{ public: Test(){}; void print(){ std::cout << "OK" << std::endl ; }; };
8
by: FBM | last post by:
Hi there, I am puzzled with the behavior of my code.. I am working on a networking stuff, and debugging with eclipse (GNU gdb 6.6-debian).. The problem I am experiencing is the following: ...
2
by: Jan Obrestad | last post by:
Hello, I've been using the XmlReader class to read xml files. Lately it has had some strange quirks. It seems to ignore elements when there is no whitespace between them. ex...
2
by: Johnny Jörgensen | last post by:
I've got a process I want to run in a thread separate from my main application thread, so I've used a backgroundworker component, and in frmMain.Load I invoke the code using...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.