Additon of primary keys did not fix the problem ora-01779
CREATE TABLE ORDERS
(ORDER_NO NUMBER(1),
ITEM_NO NUMBER(3),
ITEM_NAME VARCHAR2(60),
ITEM_PRICE NUMBER(10));
/
CREATE TABLE ITEMS
(ITEM_NO NUMBER(3),
ITEM_NAME VARCHAR2(60),
ITEM_PRICE NUMBER (10));
/
INSERT INTO ORDERS (ORDER_NO,ITEM_NO) VALUES (1,101);
INSERT INTO ORDERS (ORDER_NO,ITEM_NO) VALUES(2,101);
INSERT INTO ORDERS (ORDER_NO,ITEM_NO) VALUES(3,111);
INSERT INTO ORDERS (ORDER_NO,ITEM_NO) VALUES(4,101);
/
INSERT INTO ITEMS(ITEM_NO,ITEM_NAME,ITEM_PRICE) VALUES (101,'CAMERA',300);
INSERT INTO ITEMS(ITEM_NO,ITEM_NAME,ITEM_PRICE) VALUES (111,'DVD',12);
/
update ( select a.item_name a_item_name, a.item_price a_item_price,
b.item_name b_item_name, b.item_price b_item_price
from orders A, items B
where a.item_no = b.item_no )
set a_item_name = b_item_name,
a_item_price = b_item_price;
SQL> update ( select a.item_name a_item_name, a.item_price a_item_price,
2 b.item_name b_item_name, b.item_price b_item_price
3 from orders A, items B
4 where a.item_no = b.item_no )
5 set a_item_name = b_item_name,
6 a_item_price = b_item_price
7 /
set a_item_name = b_item_name,
*
ERROR at line 5:
ORA-01779: cannot modify a column which maps to a non key-preserved table
ORA-01779 cannot modify a column which maps to a non key-preserved table
Cause: An attempt was made to insert or update columns of a join view which map to a non-key-preserved table.
Action: Modify the underlying base tables directly.
SQL> alter table orders add constraint o_pk primary key(Order_no);
Table altered.
SQL> update ( select a.item_name a_item_name, a.item_price a_item_price,
2 b.item_name b_item_name, b.item_price b_item_price
3 from orders A, items B
4 where a.item_no = b.item_no )
5 set a_item_name = b_item_name,
6 a_item_price = b_item_price ;
set a_item_name = b_item_name,
*
ERROR at line 5:
ORA-01779: cannot modify a column which maps to a non key-preserved table
SQL> alter table items add constraint i_pk primary key(item_no,item_name);
Table altered.
1 update ( select a.item_name a_item_name, a.item_price a_item_price,
2 b.item_name b_item_name, b.item_price b_item_price
3 from orders A, items B
4 where a.item_no = b.item_no )
5 set a_item_name = b_item_name,
6* a_item_price = b_item_price
SQL> /
set a_item_name = b_item_name,
*
ERROR at line 5:
ORA-01779: cannot modify a column which maps to a non key-preserved table