Re: Why use it : SELECT 1 FROM DUAL

From: Rodd Holman <rodd.holman_at_gmail.com>
Date: Thu, 2 Aug 2012 13:19:56 -0500
Message-ID: <CAP7tgav=x8mEgDsFbvSLiL2fA31xMvJv8VdaHPn-ckE_4GtM3w_at_mail.gmail.com>



I also use it in debugging and tuning. By putting the Where 1=1 in I can add/comment other conditions testing plans and responses SELECT f1, f2, f3
  FROM t1
 WHERE 1=1
    AND cond1
    AND cond2
    AND cond3

Changing the conditions just requires adding an and statement or "--" before an existing one.

On Thu, Aug 2, 2012 at 1:00 PM, Tim Gorman <tim_at_evdbt.com> wrote:

> Lots of developers, when generating SQL statements dynamically, use the
> predicate "1 = 1" or something similar so as not to leave an "AND"
> keyword dangling without a predicate. So, for example they'll have an
> IF-THEN-ELSE condition in the code building the SQL statement that
> generates an actual predicate in the THEN condition and hard-codes the
> no-op of "1 = 1" in the ELSE condition.
>
> It's an artifact of a slightly clumsy programming method, rather than
> any form of optimization.
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>

--
http://www.freelists.org/webpage/oracle-l
Received on Thu Aug 02 2012 - 13:19:56 CDT

Original text of this message