Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contradictory Oracle query result

Tags:

sql

oracle

I perform two queries and get strange result. I'd like to know why is this happening.
Now queries:

SELECT * FROM TABLE_A a, TABLE_B b, TABLE_C c
  WHERE a.a = b.a (+)
  AND b.c = c.c
  AND a.a = 123;

Result is empty.

SELECT COUNT(*) FROM TABLE_A a, TABLE_B b, TABLE_C c
  WHERE a.a = b.a (+)
  AND b.c = c.c
  AND a.a = 123;

Result is 1.

It is really the same query with different returned value.
Table A contains row with 'a' field = 123.
Table B does not contain rows as a.a = b.a.

How can nothing or 1 be returned for the same query?


Update:

When I make it this way

SELECT COUNT(*) FROM TABLE_A a, TABLE_B b, TABLE_C c
  WHERE a.a = b.a (+)
  AND b.c = c.c (+)
  AND a.a = 123;

It works OK.

like image 927
Arcane Avatar asked Jan 16 '12 14:01

Arcane


People also ask

How to use LIKE condition in Oracle?

To process the LIKE conditions, Oracle divides the pattern into subpatterns consisting of one or two characters each. The two-character subpatterns begin with the escape character and the other character is %, or _, or the escape character.

How to escape underscore in Oracle LIKE?

The ESCAPE clause identifies the backslash (\) as the escape character. In the pattern, the escape character precedes the underscore (_). This causes Oracle to interpret the underscore literally, rather than as a special pattern matching character.

WHAT IS LIKE operator in Oracle?

The LIKE operator returns true if the expression matches the pattern . Otherwise, it returns false. The NOT operator, if specified, negates the result of the LIKE operator.


1 Answers

Possibly you have indices or foreign key constraints that are not consistent with the table data. Since these two queries most likely use different indices, they return inconsistent data.

Have you temporarily disabled the constrataints, or set them up without validating that they have initially been valid (ENABLE NOVALIDATE)?

Try to rebuild the indices and drop and recreate the foreign key constraints to see whether that fixes your problem.

like image 53
Codo Avatar answered Nov 09 '22 12:11

Codo