Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: where 1=1 ?

Re: where 1=1 ?

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 2000/03/16
Message-ID: <ll42dsgu6fp9v8d7546r5f6sc3k7i4a7nl@4ax.com>#1/1

A copy of this was sent to Julio <julio.negueruela_at_si.unirioja.es> (if that email address didn't require changing) On Thu, 16 Mar 2000 15:47:04 +0100, you wrote:

>I'm reviewing an application we've bought to an outer company in order to (try
>to) optimize some queries they use and I've seen a lot of occurrencies of that
>strange clause show above. I.e.:
>
>select empno from emp
>where 1=1 and empdpt='COMPUTER';
>
>Does anybody wich is the utility of introducing such comparison?
>
>Regards.

they probably wanted to be able to add to the predicate without figuring out if the already started the predicate. Instead of having the base query:

select empno from emp

and then adding a predicate "where empdpt = 'x'" and then predicate "and x = 5", they started with a query:

select empno from emp where 1=1

so they can just add "AND" <condition> "AND" <condition> without worrying about whether the WHERE was already there.

Hopefully, the queries you see are really like:

select empno from emp where 1=1 and empdpt=:BV

and not hardcoded as you have. One of the #1 performance killers -- no bind variables.

-- 
http://osi.oracle.com/~tkyte/
 
Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation
Received on Thu Mar 16 2000 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US