'ORA-22806 (not an object or REF) on Join to a view

Here is a fairly simple query that is throwing this error:

SELECT RR.REQUEST_ID
FROM CCS_REQUEST_RESPONSE RR 
INNER JOIN VW_STUDENT_CURRENT_AND_HIST VW
ON RR.STUDENTID = VW.STUDENT_NUMBER

This only happens when joining to the view.
The view is a simple union all of 2 identical tables. When I substitute a single table instead of the view in the above query, it works fine.

So,

SELECT RR.REQUEST_ID
FROM CCS_REQUEST_RESPONSE RR 
INNER JOIN HISTORICAL_STUDENTS VW
ON RR.STUDENTID = VW.STUDENT_NUMBER

Works just fine.

And here is the view:

 CREATE OR REPLACE VIEW "VW_STUDENT_CURRENT_AND_HIST" ("STUDENT_NUMBER") AS 
  SELECT "STUDENT_NUMBER"
    FROM HISTORICAL_STUDENTS
UNION ALL
  SELECT "STUDENT_NUMBER"
      FROM CURRENT_YEAR_STUDENTS;

Interesting thing is that this used to work and suddenly stopped. Any ideas?



Solution 1:[1]

SOLVED.

The two tables in the view, though identical in respect to field names and definitions had a different field order.
I dropped and recreated one of the tables using the same DDL as the other and it's now working fine.

I don't know why that would be a problem, but maybe someone else can answer that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user1477214