Question: : I have seen a SQL statement
in my database that looks like this where 1=1:
Select stuff from mytab where 1=1;
What is the point in adding 1=1 to a SQL query?
Answer: In PL/SQL systems, dynamic SQL is
created using the EXECUTE IMMEDIATE clause.
In these systems, the end-user specifies query filtering
conditions, but sometime they will have no conditions at all,
meaning that no WHERE clause is required in the dynamic SQL.
In sum, the “where 1=1” is a used as a placeholder for the WHERE
clause so that ah-hoc filtering predicates can be easily added to
the query, and the query will execute, even in the absence of
specified filtering conditions.
Also, see these notes on
SQL with “where 1=2”.
Get the Complete
Oracle SQL Tuning Information
The landmark book
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
for 30% off directly from the publisher.