[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ORA-01779: cannot modify a column which maps to a non key-preserved table on update

Posted on 2012-08-29
4
Medium Priority
?
709 Views
Last Modified: 2012-09-02
Consider the following table:
create table order_line_package(
  Order_Line_Package_Id number(19,0) not null,
  Order_Package_Id number(19,0) not null,
  Order_No number(10,0) not null,
  Project_No varchar(8) not null,
  Entity varchar(15) not null,
  Line_No number (6,2) not null,
  Packed_Quantity number (10,2) not null
)  
ALTER TABLE order_line_package 
    ADD CONSTRAINT order_line_package_PK PRIMARY KEY ( Order_Line_Package_Id ) ;
ALTER TABLE order_line_package 
    ADD CONSTRAINT order_line_package_unq 
      unique( Order_No, Project_No, Entity, Line_No, order_package_id ) ;

Open in new window


I'm trying to execute the following update in order to combine the quantity of a like items:

    update (
      select sl.packed_quantity source_package_qty, dl.packed_quantity dest_package_qty
      from order_line_package sl --source lines
        join order_line_package dl --destination lines
          on sl.Order_No = dl.Order_No
          and sl.Project_No = dl.Project_No
          and sl.Entity = dl.Entity
          and sl.Line_No = dl.Line_No
          and sl.order_package_id = source_package_rec.order_package_id
          and dl.order_package_id = dest_package_rec.order_package_id
    ) set dest_package_qty = dest_package_qty + source_package_qty
    ;

Open in new window


Why do i get the 01779 error in this case?  To me, the destination table is key preserved since all columns of the unique constraint are part of the join.
0
Comment
Question by:b_levitt
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38346023
this happens when the relationship is not necessarily one-to-one between the tables.

better to a update/join syntax:
http://www.experts-exchange.com/Database/Miscellaneous/A_1517-UPDATES-with-JOIN-for-everybody.html
0
 
LVL 11

Author Comment

by:b_levitt
ID: 38346366
I guess that's part of my question.  I'm using all columns in a unique constraint so how could it not be one to one?  I think the fact that I'm providing a constant for either side of the final column in that constraint rater than joining it together (which of course is impossible since it would violate the constraint) and that is confusing oracle.

I do appreciate the alternative methods though, thank you.
0
 

Expert Comment

by:Gunasekaraneswaran
ID: 38350966
I guess the join sl.order_package_id = dl.order_package_id is missing and without this join the values may not be unique.

May be the query should be

 update (
      select sl.packed_quantity source_package_qty, dl.packed_quantity dest_package_qty
      from order_line_package sl --source lines
        join order_line_package dl --destination lines
          on sl.Order_No = dl.Order_No
          and sl.Project_No = dl.Project_No
          and sl.Entity = dl.Entity
          and sl.Line_No = dl.Line_No
          and sl.order_package_id = dl.order_package_id
          and sl.order_package_id = source_package_rec.order_package_id
--          and dl.order_package_id = dest_package_rec.order_package_id
    ) set dest_package_qty = dest_package_qty + source_package_qty
    ;
0
 
LVL 11

Author Closing Comment

by:b_levitt
ID: 38359634
In the end I'm a little disappointed that oracle only supports very simple equijoins with this syntax.  I ended up using the update via correlated query with the exists clause in angelIII's article.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question