Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Looking to replace 1=1 in where clause with something more efficient...

user6248369Jun 6 2018 — edited Jun 6 2018

Hello,

I'm looking to replace 1=1 in Where clause with something more efficient and elegant. I have searched but did not find what was I looking for. There are tons of questions about what 1=1 means, etc... Here's the simple query:

SELECT zip, zip_city FROM

(

    SELECT 10952 zip, 'AIRMOUNTAIN' zip_city, 'RUCKLAND' zip_county, 'AR' zip_state FROM dual

    UNION ALL

    SELECT 10952 zip, NULL zip_city, NULL zip_county, 'AR' zip_state FROM dual

)

WHERE (zip_city = '&p_city' OR 1=1)

/

The parameter &p_city may or may not be null. Passing null to p_city will return no rows w/out 1=1. Is there any better, more efficient, elegant way to do the same please?
Thank you very much.

This post has been answered by Frank Kulash on Jun 6 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2018
Added on Jun 6 2018
26 comments
1,461 views