Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to make an update of an inline view of two tables ...

user653360Sep 17 2008 — edited Sep 17 2008
when the unique constraint of the second table includes three columns?

I have two tables A and B and I want to update a column in table A using an update of an inline view of the two tables.

Table A:
col1 primary key
col2

Table B:
col1 u1
col2 u2
col3 u3
col4
col5

Table A has col1 as primary key, table B has a unique constraint over col1, col2 and col3.

Table A and table B are joined in this way:
select  A.col1, A.col2 as KEY_OLD, B.col5 as KEY_NEW
from    A, B
where (B.col1 = 'literal_1') and (B.col2 = 'literal_2') and (A.col1 = B.col3) and (A.col2 = B.col4)
And now I want to update this view and set KEY_OLD = KEY_NEW.

Because of the first three conditions in the where-clause for every entry in table A there is just one matching entry in table B.
So the table A should be key-preserved in the join.

But when making the update
update (select  A.col1, A.col2 as KEY_OLD, B.col5 as KEY_NEW
            from    A, B
            where (B.col1 = 'literal_1') and (B.col2 = 'literal_2') and (A.col1 = B.col3) and (A.col2 = B.col4)
           )
set     KEY_OLD = KEY_NEW;
I get an error ORA-01779.

I have made updates on inline views in this way many times in the last weeks and it work very good.
But until now the unique contstraint on table B had just one column;-)

So what I need is to get it working with the unique constraint on table B applying to three columns.

Many thanks in advance for any help.

Regards Hartmut
This post has been answered by 94799 on Sep 17 2008
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 15 2008
Added on Sep 17 2008
8 comments
1,865 views