Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What I Achieve by recompiling a view ?

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two questions.

First One is
I created a table as

create table pg(id number,name varchar2(30));

then I created a view as

create view pgview as
select id,name
from pg;

then I changed the datatype of column id as

alter table pg
modify id varchar2(10);

Now I queried the view User_objects and it shows the status of pgview as INVALID

then I inserted a row in the table pg and again queried the view User_objects now it shows the status as VALID.

My question is how status changes from INVALID to VALID .


My second quastion is

Suppose I rename a column or drop a column of a table , and that column was included in the view.
Now That view have no meaning ,Even If I try to recompile the view it will say "View altered with compilation errors"
I have to create the view a new altogether.

Now suppose rather than renaming or dropping the column I just change the datatype of the column ,and that column was included in the view.
Now Even If I don`t recompile the view it works ok.

So what I achieve from the statement " alter view view_name compile "

Shukran...

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Invalid objects in Oracle are automatically recompiled when used. Consider
2) You'll use alter view view_name compile to compile it explicitly, without waiting for it to be used. Typical use would be in schema upgrade scripts, for example - you don't want to wait for the view to be used by an application or user to be compiled, you want to catch any possible problems early.

Edit: I'd suggest reading Oracle's Database Concepts Guide, lots of questions you've asked lately are well covered there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic