HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Compile Views in Oracle

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
viewsoraclecompile

Problem

I am currently running a very long script in Oracle for our production but we are having discrepancies in the data.

As I checked the views that the script is using (I am using Toad), I see an X mark beside the view name, then I saw an option to compile it.

I am wondering if what does a compile in a view means? Is the view not updated which causes discrepancy in the data?

Solution

If you ALTER a table that is referenced by a view, or even DROP a table, the view is marked as invalid and can't be accessed even if the changes to the table(s) would not make the view's code incorrect.

In that case the view needs to be re-compiled:

ALTER VIEW some_view COMPILE;


More details in the manual:

https://docs.oracle.com/database/121/SQLRF/statements_4004.htm#SQLRF01104

Code Snippets

ALTER VIEW some_view COMPILE;

Context

StackExchange Database Administrators Q#166069, answer score: 7

Revisions (0)

No revisions yet.