Does Oracle begin the SQL Query WHERE clause with 1 = 1 useful?

I work with a client that runs almost all of its WHERE clauses in Oracle with 1=1. Forgive my ignorance, but is it not-op? Are there any negative consequences of this use?

Here is an example:

SELECT   gpz.zname
         ,gpp.pname
FROM     table1 gpp INNER JOIN table2 gpz ON gpz.p_id = gpp.p_id
WHERE    1=1
         AND gpp.active = 1
         AND gpz.active = 1
+5
source share
3 answers

This is done to simplify the dynamic generation of SQL. Basically, each condition can be added as AND <condition>without treating the first condition as special (it is WHEREnot preceded by it AND) or even worry about whether the creature should even have a sentence WHERE.

, , .

+18

, , . , , SQL Injection.

where 1 = 1 and my_id = :b1;

( )

, :

where 1 = 1 and my_id = 123456;
+3

, .

AND s, -, , .

.

0

All Articles