To find why Oracle returns wrong results, first pin down exactly what is wrong, then check the most common and most reversible causes in order: session-level NLS and date handling, query and optimizer behavior, transaction and isolation visibility, and finally data or index corruption. The fastest path is a reproducible test case—a single query and the smallest data set that shows the mismatch—run with ALTER SESSION SET EVENTS '10046 trace name context forever, level 12' when you need execution detail. Most "incorrect" results turn out to be correct results for different session settings, stale statistics, or a misunderstanding of how Oracle compares and sorts values, not a bug in the database.

The order below moves from cheap, reversible checks to invasive ones. Stop after each step if you've found the cause, and don't change production settings until you understand which session or statement is affected. Version matters throughout: behavior of the optimizer, date formats, empty strings, and sort order has shifted across Oracle releases, so note your exact version from v$version before drawing conclusions.

Start by defining "incorrect" in one reproducible test case

Before touching any Oracle parameter, write down what the query returns and what you expected, then reduce both to something another person could run. "Incorrect" usually means one of four things: a row that should be there is missing, an extra row appears, a column value is wrong, or rows come back in an unexpected order. Each points to a different cause, so classify the symptom first.

Build the case like this:

1: Capture the exact SQL text, including any WHERE clause, ORDER BY, bind values, and the schema objects it touches. Get it from v$sql or your application log if you can't see it directly. 2: Copy the smallest relevant rows into scratch tables—often a handful is enough—and confirm the query still produces the wrong result against the copy. If it doesn't, your original depends on data you haven't captured. 3: Record the session environment: NLS_DATE_FORMAT, NLS_SORT, NLS_COMP, OPTIMIZER_MODE, and the schema you're connected as. Run SELECT * FROM nls_session_parameters and save the output. 4: Note whether the result changes between runs, between sessions, between the application and a SQL client, and before versus after a restart. Each pattern narrows the field substantially.

A test case that you can re-run on demand is the difference between guessing and diagnosing. If your "wrong" result only appears in the application and never in a client tool, the application's connection settings or bind handling is part of the problem, and the test case must reproduce that environment—same NLS settings, same bind types, same schema.

Success check: a colleague or a second session can run your test case and see the same mismatch. If they can't, you don't have a reproducible problem yet, and every later step is guesswork.

Rule out session settings and implicit conversions first

The single most common source of "incorrect" Oracle results is a session or database setting that changes how values are compared, displayed, or converted. These are cheap to check and easy to reverse, so they come before anything involving the optimizer or storage.

Date and timestamp comparisons are the classic trap. A literal like '13-NOV-26' is interpreted according to NLS_DATE_FORMAT, so the same query can match different rows in two sessions with different formats. Worse, comparing a DATE to a string forces an implicit conversion, which can make a predicate silently non-selective or shift a boundary by hours. The fix is explicit: use TO_DATE('2026-11-13','YYYY-MM-DD') or DATE '2026-11-13', and compare like types. Check whether a missing or extra row sits exactly on a midnight boundary; that detail alone often identifies the cause.

Numeric-to-character and character-to-numeric conversions cause similar surprises. WHERE account_id = '00123' behaves differently against a VARCHAR2 column and a NUMBER column, and leading zeros, spaces, or non-numeric characters can throw errors or truncate comparisons. Watch for implicit conversions by running the query's EXPLAIN PLAN; a TO_NUMBER or TO_CHAR wrapped around a column in the predicate means an implicit conversion is happening.

NLS_COMP and NLS_SORT affect string comparison. With binary sorting, 'a' and 'A' are distinct and sort separately; linguistic settings can make them equivalent or order them differently. If rows are "missing" only when case or accents differ, the session's comparison semantics are the likely culprit.

Sort-order symptoms point the same way. An ORDER BY that returns a different sequence in two sessions usually reflects different NLS_SORT values, not a data problem.

To confirm, re-run the test case in a fresh session with the settings you expect, then compare. If the result becomes correct, you've found the cause; the remaining work is deciding whether to fix the query (explicit conversion, explicit NLSSORT) or the session setup. Changing the session is usually the safer fix, since it doesn't rewrite application logic.

Check transaction visibility and isolation

If the result is wrong only intermittently, or differs between the application and a direct query, look at what each session can see. Oracle's read-consistency model means a long-running query sees data as of its start time, while a committed change made after that point remains invisible to it. That's correct behavior, but it produces "stale" or "missing" rows that look like errors.

A few specific patterns are worth checking:

Uncommitted changes. A session that made an INSERT or UPDATE but hasn't committed sees its own changes; other sessions don't. If you're reproducing in the same session that made the change, you'll get a different answer than any other user. Sequence and identity values. Sequence numbers are assigned at insert time but become visible to other sessions only after commit, so ORDER BY id can disagree with ORDER BY created_at across sessions. Read consistency across a long transaction. A query that runs for minutes sees a consistent snapshot from its start. If the data changes underneath it, later queries in the same transaction may show a different picture, and a comparison of the two will look like an inconsistency. SERIALIZABLE versus READ COMMITTED. Sessions in SERIALIZABLE isolation can get ORA-08177 rather than a wrong result, but a session that silently falls back or a statement rewritten under different isolation can return a different row set.

The check: run the same test case in two fresh sessions, changing data only between separate committed transactions. If the results agree, visibility isn't the cause. If they disagree, note which session made the change and whether it committed before the query started. SELECT * FROM v$transaction and v$session will show open transactions that might explain the discrepancy.

Investigate the optimizer and execution plan

Once settings and visibility are ruled out, the next layer is how Oracle chose to execute the statement. A wrong plan doesn't usually produce logically incorrect results—the relational answer is fixed by the query—but it can expose bugs, and it's a frequent cause of "the query used to work" complaints that are actually plan regressions.

Start with EXPLAIN PLAN FOR and DBMS_XPLAN.DISPLAY, or better, capture the actual plan with DBMS_XPLAN.DISPLAY_CURSOR after the query runs, since the plan Oracle actually executed can differ from the predicted one. Compare the plan in the failing session against a session where the query works. Look for:

A predicate that vanished from the plan or was pushed to a place where it filters differently. A conversion on a column that prevents index use and changes which rows survive a join. A join method or order change that, combined with a bug in a specific release, produces wrong rows.

If the plan differs, force it with a hint such as /*+ INDEX(t idx_name) */ or, more reliably, an SQL plan baseline, and re-run the test case. If the answer becomes correct with a forced plan, you've found a plan-dependent issue—then check whether the difference stems from statistics, a parameter, or a known bug in your version.

Statistics are the usual root cause. Stale or missing statistics make the optimizer guess, and a bad guess can pick a plan that behaves incorrectly in edge cases. Compare LAST_ANALYZED in USER_TAB_STATISTICS against recent data volume changes, and check whether a column's distinct-value count is wildly off by querying USER_TAB_COL_STATISTICS. Regathering statistics with DBMS_STATS.GATHER_TABLE_STATS is reversible if you keep the old statistics with DBMS_STATS.EXPORT_TABLE_STATS first, so it's a safe experiment.

A specific failure worth testing: a predicate on a VARCHAR2 column with mixed alphanumeric values, where an implicit conversion to NUMBER or DATE in an older release could evaluate a filter in an order that changed which rows were compared—and in a few releases, which rows passed. If the query includes an implicit conversion and the plan uses a function-based predicate, that's a high-probability suspect.

Test with optimizer features toggled

If the plan looks reasonable but the result is still wrong, the next reversible check is to change optimizer behavior at session level and see whether the answer changes. This isolates whether the difference comes from a query transformation or a costing decision. Run each test against a copy of your test case, record the result, and restore settings afterward.

Useful toggles, all session-scoped and reversible:

The optimizer_features_enable approach is the most useful: it makes the session behave as if it were an older patch level, which is exactly how you test whether a regression arrived in a recent release. Run the test case with the current setting, then with a version from before your last upgrade. If the older setting gives the correct answer, you have a strong signal that the cause is a release-specific behavior change, and you can narrow it with optimizer_features_enable to the exact version where it appeared.

Two cautions. These toggles can change performance dramatically, so never leave them set in production on a shared session. And an ALTER SESSION only affects new statements—the existing cursor keeps its original plan, so start a new session or use DBMS_SQL to be sure.

Success check: the answer flips predictably with the toggle, in both directions. If it doesn't, the optimizer is not the cause and you should move on.

Look for data-level and index-level causes

When session settings, visibility, and the optimizer are all cleared, the remaining category is corruption or inconsistency in the stored data or indexes. This is rarer but more serious, and it moves the work from configuration into storage.

Start with the cheapest check: ANALYZE TABLE ... VALIDATE STRUCTURE CASCADE (or DBMS_STATS for statistics) confirms the table and its indexes are structurally sound. DBMS_REPAIR can identify corrupt blocks, and RMAN backup validation plus DBMS_REPAIR.CHECK_OBJECT will tell you whether specific blocks are damaged. A wrong result that appears for specific primary keys or ranges, but not others, is a classic sign of a corrupted index entry pointing at the wrong row.

Index corruption has a characteristic symptom: the answer is wrong when accessed via an index, but correct with a full table scan. Test this directly by running the test case with /*+ FULL(t) */ on the relevant table. If the full-scan answer is correct and the index-driven answer is wrong, the index is suspect—rebuild it with ALTER INDEX ... REBUILD after confirming a valid backup exists, and compare. This is a reversible experiment only in the sense that the rebuild is regenerable from the table; if the table data itself is off, the rebuild won't help.

Data-level inconsistency, where two tables that should agree don't, is best checked by comparing aggregates independently: sum a column from both sides, count rows by a shared key, and see where the totals diverge. A difference that survives a full scan of both tables means the data is genuinely inconsistent, and the cause is upstream—an application bug, a failed load, or a trigger doing something you didn't expect.

One more data-level suspect worth naming: character encoding. If one table was loaded with a different character set or NLS_CHARACTERSET, values that "look" identical in different tools may compare as unequal. DUMP the column value on both sides of the comparison and compare the byte sequences.

At this point, if you've isolated corruption or an internal inconsistency, stop changing production data. Rebuilding indexes and gathering statistics is safe; running DBMS_REPAIR on a production table is not, and the next step is your DBA team and Oracle Support with the test case, the version, and the trace output.

Capture evidence to hand off or escalate

The diagnosis is only as good as the evidence you can reproduce. Before escalating—or before making a change you can't easily undo—collect a small, portable package.

1: Record the exact version: the full string from SELECT banner FROM v$version, not just "19c." 2: Save the minimized test case: the DDL and inserts, the query, the observed result, and the expected result. 3: Capture the execution plan with DBMS_XPLAN.DISPLAY_CURSOR and the session's NLS settings side by side. 4: If possible, gather an optimizer trace for the specific statement with ALTER SESSION SET EVENTS '10053 trace name context forever, level 1', run the query once, and turn the event off. The trace is large and version-specific, so keep it to a single statement. 5: Note the exact sequence of session state changes and the version of optimizer_features_enable that produced the correct answer.

The success check for the whole exercise is that someone else can take your package, run it in a test environment, and reproduce both the wrong answer and the condition that produces the right one. When you can do that, the "cause" is no longer a suspicion—it's a documented finding. If you can't, the honest conclusion is that the remaining candidates are a known release bug, and the next move is Oracle Support with the trace and test case, not another production change.