Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 162349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:22:29+00:00 2026-05-11T11:22:29+00:00

I’ve come across a query in an application that I’ve inherited that looks like

  • 0

I’ve come across a query in an application that I’ve inherited that looks like this:

Select * From foo where     1 <> 1 

As I parse that, it should return nothing (1 <> 1 should evaluate to false, right). However (at least on my Oracle box) it comes back with a full listing of everything in foo. When I try the same thing in MSAccess/Jet and MSSQL I get the behaviour I expect. Why is it different for Oracle (and why would the original developer want to do this)?

Note: I’ve seen some superstition about the +s and -s of using ‘where 1 = 1’, and it causing full table scans; but I don’t think this is what the original developer was intending.

Small Update:
In this case foo is a view. When I try the same thing on on an actual table, I get what I would expect (no rows).

Update 2:
I’ve following the code further down the rabbit hole and determined that all he’s doing is trying to grab the field/column names. I’m still at a loss as to why it’s returning the full record set; but only on views.

Literally, he’s building the query in a string and passing it on for another function to execute unaltered.

'VB6 strSQL = 'SELECT * FROM ' & strTableName & ' WHERE 1 <> 1' 

In this case strTableName contains the name of a view.

Update 3:
For reference, here is one of the views I’m having problems with (I’ve changed the field/table/schema names)

CREATE OR REPLACE FORCE VIEW scott.foo (field1,                                         field2,                                         field4,                                         field5,                                         field12,                                         field8,                                         field6,                                         field7,                                         field16,                                         field11,                                         field13,                                         field14,                                         field15,                                         field17                                        ) AS    SELECT   bar.field1,             bar.field2,             DECODE                (yadda.field9, NULL, 'N',                 DECODE (yadda.field3, NULL, 'Y', 'N')                ) AS field4,             bar.field5,             snafu.field6,             DECODE                 (snafu.field6,                  NULL,                 bar.field8,                    bar.field8                  - snafu.field6                 ) AS field7,             DECODE                (yadda.field10,                 NULL,             bar.field12,                 yadda.field10                ) AS field11,             DECODE                (SIGN (  yadda.field10 - bar.field12),                 NULL, 'N', 1, 'N', 0, 'N', -1, 'Y'                ) AS field13,             bar.field14,             ADD_MONTHS                (DECODE (yadda.field10, NULL, bar.field12, yadda.field10                        ),                 bar.field14 * 12                ) AS field15,        FROM clbuttic,             bar,             yadda,             snafu       WHERE clbuttic.asset_type = bar.asset_type         AND bar.field16 = yadda.field9(+)         AND bar.field1 = snafu.field1(+)         AND (bar.field17 IS NULL)    ; 

Appending Order By 1 (or some column name in the select on foo) seems to convince Oracle to give me back the empty set. It’s a long term solution, but not a short term one (changing he code and redeploying is a major PITA). I’m hoping there’s a little known setting on the DB side or something wrong in the View that is the cause of this odd behaviour.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:22:30+00:00Added an answer on May 11, 2026 at 11:22 am

    It definitely looks like a bug in the view merging code of the Oracle optimizer. I bet you only get this with views which contain outer joins. Your ORDER BY solves it, because it practically forces a NO_MERGE on the view.

    I wouldn’t put either an ORDER BY or a NO_MERGE hint inside the view though, because (depending on your data volume) it could degrade performance of other queries which use the view. You should put a no_merge hint in the outer query:

    Select /*+ NO_MERGE(foo) */ * From foo where     1 <> 1 

    You should also raise an SR with Oracle support, as this is definitely a bug. That query should never ever return any rows no matter what you are selecting from, or how complex it is inside. Never ever.

    I couldn’t reproduce it, so it’s probably fixed in the version I’m using. What’s the db version you are using?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.