Home » SQL & PL/SQL » SQL & PL/SQL » What is the Difference b/w Up datable Views and Non-Up datable Views their uses (Oracle 11g)
icon5.gif  What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643173] Thu, 01 October 2015 01:07 Go to next message
graphe
Messages: 23
Registered: October 2014
Junior Member

Can Anybody tell me
What is the Main Difference Between Updatable View's and Non- updatable View's And their Uses At What situations
Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643174 is a reply to message #643173] Thu, 01 October 2015 01:16 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

One can be update and the other one can't.
Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile Smile

[Updated on: Thu, 01 October 2015 01:16]

Report message to a moderator

Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643177 is a reply to message #643174] Thu, 01 October 2015 01:30 Go to previous messageGo to next message
graphe
Messages: 23
Registered: October 2014
Junior Member

Can you Please Explain that With Syntaxes Embarassed Embarassed Embarassed
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643187 is a reply to message #643177] Thu, 01 October 2015 02:58 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
There is no difference in syntax. A view is updatable as long as the query doesn't contain something that prevents it from being updatable. See the create view page in the docs for the list of restrictions.
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643190 is a reply to message #643187] Thu, 01 October 2015 03:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

There is one case with the syntax: adding a "read only" constraint in the view definition.

Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643204 is a reply to message #643190] Thu, 01 October 2015 03:58 Go to previous messageGo to next message
graphe
Messages: 23
Registered: October 2014
Junior Member

Can you give a Full syntax of Both with One Example Smile Smile Smile Smile Smile
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643209 is a reply to message #643204] Thu, 01 October 2015 04:21 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
Have you read the create view doc page yet?
icon10.gif  Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643212 is a reply to message #643209] Thu, 01 October 2015 05:15 Go to previous messageGo to next message
graphe
Messages: 23
Registered: October 2014
Junior Member

kk i read that docs at oracle thanksss Mr. Cookie
Laughing Laughing Laughing Cool Cool Cool Smile Smile
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643215 is a reply to message #643212] Thu, 01 October 2015 05:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Note your post are unprofessional.
This site is a quite popular professional one (and not facebook or tweeter or your favorite social site) and your future boss will likely read what you posted.
Smileys must be sparingly used and only to clarify or emphasize some points.

Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643218 is a reply to message #643215] Thu, 01 October 2015 05:44 Go to previous messageGo to next message
graphe
Messages: 23
Registered: October 2014
Junior Member

kk i understood i m sorry
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643220 is a reply to message #643218] Thu, 01 October 2015 05:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

The same remark applies to SMS/IM speak: never do that in a professional forum.

Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643307 is a reply to message #643220] Sun, 04 October 2015 00:25 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
Originally, an updateable view was defined as a view which "preserves the primary key of the base table of the view" and thus makes it possible for the view to know which row is to be updated and can locate that row in the database at update time. Accordingly to this early definition, views that do not present a direct mapping of a root row back to an underlying table row are not updateable in this sense. Additionally this implies that your database is correctly using constraints (PRIMARY KEY / UNIQUE KEY / FOREIGN KEY) so that the view can map what you want to update.

However, there are additional cases where primary key need not be defined and the view in still updateable, and other cases where this "IDEAL" definition is not fully implemented. The basic rule then is: CAN THE VIEW FIGURE OUT WHAT ROW NEEDS TO BE UPDATE? If it can, then the view is updateable. To that end, most people tend to define an updateable view by coming at it from the other direction, and describing what makes a view "NOT UPDATEABLE". They often point to aggregation as one thing that makes a view non-updateable but even that is not correct.

It is certainly confusing, more so given that different database products support updateable views to more or less degrees. Consider however, this code stream and errors it generates, and what each error is telling you. In particular pay attention to the last case as this error indicates that though the update was rejected, it is an updateable view.

drop view v5;
drop view v4;
drop view v3;
drop view v2;
drop view v1;
drop table t2;
drop table t1;

---------------------------------------------------------------------------------------

create table t1 (c1 integer);
insert into t1 values (1);
insert into t1 values (1);
insert into t1 values (1);
insert into t1 values (1);
commit;
select* from t1;
create view v1 as select * from t1;
update v1 set c1 = 2;

4 rows updated.

There is no PRIMARY KEY defined here, yet the view has no difficulty deciding what rows to update.

---------------------------------------------------------------------------------------

create table t2 (c1 integer, c2 integer);
insert into t2 values (2,1);
insert into t2 values (2,1);
insert into t2 values (2,1);
insert into t2 values (2,1);
commit;
select * from t2;
create view v2
as
select t1.c1,t2.c2
from t1,t2
where t2.c1 = t1.c1
/
update v2 set c1 = c1;

update v2 set c1 = c1
              *
ERROR at line 1:
ORA-01779: cannot modify a column which maps to a non key-preserved table

OK so technically this error is a lie since the first example was also of a non key-preserved table but it was still updateable.

Seems adding a join causes a problem.  But this may be due to the goofy data model shown, let us correct that.

---------------------------------------------------------------------------------------

update t1 set c1 = rownum;
update t2 set c1 = rownum;

select * from t1;
select * from t2;

commit;

alter table t1 add primary key (c1);
alter table t2 add primary key (c1);

update v2 set c1 = c1+100;

4 rows updated.

Seems after we make the data right and define primary keys on the tables, we can update the join view no problem.
After the update the data will no longer be retrievable since the keys between tables will no longer match but the view is still updateable.

01:03:12 SQL> select* from t1;

        C1
----------
       101
       102
       103
       104

4 rows selected.

Elapsed: 00:00:00.03
01:03:16 SQL> select* from t2;

        C1         C2
---------- ----------
         1          1
         2          1
         3          1
         4          1

4 rows selected.

Elapsed: 00:00:00.04

---------------------------------------------------------------------------------------

but the above example is actually also not realistic.
Let us define the missing foreign key as well and redo the update.

rollback;

alter table t2 add foreign key (c1) references t1;

update v2 set c1 = c1+100;

update v2 set c1 = c1+100
*
ERROR at line 1:
ORA-02291: integrity constraint (KEVIN.SYS_C0010352) violated - parent key not found

This tells us that the join view is updateable, but that since we are updating the primary key, and our FK is not deferred, this update will not work.

---------------------------------------------------------------------------------------

create or replace view v3
as
select c1,count(*) rowcount
from t2
group by c1
/

update v3 set c1 = c1+100;

update v3 set c1 = c1+100
       *
ERROR at line 1:
ORA-01732: data manipulation operation not legal on this view

A different error.  Seems this group view is not updateable.
In this case this makes sense since there is no identifiable row to update.
Being true aggregate rows, no row in this view maps to any table used in the view.

---------------------------------------------------------------------------------------

create or replace view v4
as
select t1.c1,count(*) rowcount
from t1,t2
where t1.c1 = t2.c1
group by t1.c1
/

update v4 set c1 = c1+100;

update v4 set c1 = c1+100
       *
ERROR at line 1:
ORA-01732: data manipulation operation not legal on this view

Hmm... this however does not make sense.
There is no problem knowing what row to update since the primary key of the view and the primary key of the rows to be updated by the view match.
Oracle should have been able to figure this out but it cannot which tells us it is relying on a simplified implementation of the definition.
Maybe using ROWID is the basis for an Oracle database (I am guessing).

---------------------------------------------------------------------------------------

create or replace view v5
as
select t1.c1,(select count(*) from t2 where t2.c1 = t1.c1) rowcount
from t1
/

update v5 set c1 = c1+100;

update v5 set c1 = c1+100
*
ERROR at line 1:
ORA-02292: integrity constraint (KEVIN.SYS_C0010352) violated - child record found

But this variation of the view works.  Same result (ignoring the possible issue of nulls anyway) but here it updates fine.
This seems to be because the identity of the row is something the database can figure out.
The error tells us the view is updateable but also that doing the update violates other constraints.
But again, the view is updateable.



So there you go. A brief introduction to updateable views.

OK one more really interesting example for clarification:


create or replace view v6
as
select t2.c2
from t1,t2
where t1.c1 = t2.c1
/

update v6 set c2 = 9;

4 rows updated.

Understand why this works?
There are no primary keys preserved by this view (none are presented in the view result row anyway).
So this is not technically a primary key preserving view is it?
Yet the database has no problem updating table T2.
So once again it appear Oracle is no relying strictly on the old definition of "primary key preserved view" in order to determine updatability of the view.
Just saying.
Not how similar this is to view V2 yet in that case the table updated was T1.
Neat how Oracle can figure out what to update eh.


and this is also interesting.

select constraint_name from dba_constraints where table_name = 'T2' and constraint_type = 'R';

CONSTRAINT_NAME
----------------------------------------------------------------------------------------------------------------------
SYS_C0010352

1 row selected.

alter table t2 drop constraint SYS_C0010352;

update v2 set c1 = c1+100,c2 = c2+100;

update v2 set c1 = c1+100,c2 = c2+100
                          *
ERROR at line 1:
ORA-01776: cannot modify more than one base table through a join view

this and the other examples help you to start thinking about how oracle is translating your update against a view into updates against the underlying tables of the view.


Kevin

[Updated on: Sun, 04 October 2015 00:52]

Report message to a moderator

Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643354 is a reply to message #643307] Tue, 06 October 2015 00:47 Go to previous messageGo to next message
graphe
Messages: 23
Registered: October 2014
Junior Member

Thank you very much Mr.kevin for your Explanation .i understood That very clearly with some of doubts. While You are checking the execution of Query you are analysing the on which basis the query is executing.
Can you please Explain that checking the query execution on which basis (on which column or oracle generated column) it is executing . can we do this checking for each and every query execution . Please Give Some Examples i will happy if u give a positive reply
Thanks in Advance. Smile Smile
Re: What is the Difference b/w Up datable Views and Non-Up datable Views their uses [message #643356 is a reply to message #643354] Tue, 06 October 2015 01:08 Go to previous message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

New question, new topic, this one is over.

And it seems you did not understand what I said about smileys and IM/SMS speak.



Previous Topic: SQL with group by
Next Topic: oracle procedure
Goto Forum:
  


Current Time: Mon Jun 29 05:40:22 CDT 2026