Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> SQL puzzle
Hi all,
We've stumbled across a SQL puzzle that I was hoping that someone from the news group could clarify. Basically, we don't understand why one query works and another doesn't.
Statement 1 works:
SELECT LOG_RAT2N_MEAN, SPOT
FROM RESULT
WHERE EXPTID = 918
and (
(CH2IN_MEAN/CH2BN_MEDIAN >= 2 AND CH2BN_MEDIAN > 0)
AND)
(CH1I_MEAN/CH1B_MEDIAN >= 2 AND CH1B_MEDIAN > 0)
Statement 2 fails with a divison error:
SELECT LOG_RAT2N_MEAN, SPOT
FROM RESULT
WHERE EXPTID = 918
and (
(CH2BN_MEDIAN > 0 AND CH2IN_MEAN/CH2BN_MEDIAN >= 2)
AND)
(CH1B_MEDIAN > 0 AND CH1I_MEAN/CH1B_MEDIAN >= 2)
ERROR:
ORA-01476: divisor is equal to zero
The data is such that there are no 0 values for CH2BN_MEDIAN, but there are 0 values for CH1B_MEDIAN . It is as if the CH1B_MEDIAN > 0 clause in the query 2 is ignored. Both queries give the same explain plan:
QUERY_PLAN
Statement 3 works:
SELECT LOG_RAT2N_MEAN, SPOT
FROM RESULT
WHERE EXPTID = 918
and (
(CH2BN_MEDIAN > 0 AND CH2IN_MEAN/CH2BN_MEDIAN >= 2)
OR
(CH1B_MEDIAN > 0 AND CH1I_MEAN/CH1B_MEDIAN >= 2)
)
Statement 4 failed with ORA-01476 error again:
SELECT LOG_RAT2N_MEAN, SPOT
FROM RESULT
WHERE EXPTID = 918
and (
(CH2IN_MEAN/CH2BN_MEDIAN >= 2 AND CH2BN_MEDIAN > 0)
OR
(CH1I_MEAN/CH1B_MEDIAN >= 2 AND CH1B_MEDIAN > 0)
)
Thanks for any help you might be able to shed on this puzzle.
Gail Binkley
Stanford University
gail_at_genome.stanford.edu
-- Department of Genetics Phone: (650) 498-7145 School of Medicine Fax: (650) 723-7016 Stanford University Email: gail_at_genome.stanford.edu Stanford, CA 94305-5120 URL: http://genome-www.stanford.edu/Received on Tue Jan 23 2001 - 13:44:43 CST