ORA-01779: cannot modify a column which maps to a non key-preserved table
2014-02-24 14:12
477 查看
当更新一个子查询的时候,会出现这个错误。ORA-01779: cannot modify a column which maps to a non key-preserved table
下面先模拟一下这个错误:
SQL> select * from gw1;
ID NAME
---------- ----------
1 a
2 b
3 c
SQL> select * from gw2;
ID UPDATE_ID
---------- ----------
1 11
2 22
3 33
4 44
SQL> select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id;
ID UPDATE_ID
---------- ----------
1 11
2 22
3 33
SQL> update (select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id) tmp set tmp.id=tmp.update_id;
update (select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id) tmp set tmp.id=tmp.update_id
*
ERROR at line 1:
ORA-01779: cannot modify a column which maps to a non key-preserved table
产生这个错误的原因是因为gw2表的id不是唯一的,有可能gw1的一个id会对应多个gw2的id,这样就不知道怎么更新了。即使gw2的表中并不存在这样的记录。
解决方法:给gw2表的id列加上unique约束或设置为主键
SQL> alter table gw2 modify id unique;
Table altered.
SQL> update (select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id) tmp set tmp.id=tmp.update_id;
3 rows updated.
SQL> select * from gw1;
ID NAME
---------- ----------
11 a
22 b
33 c
如需转载,请注明出处:http://blog.csdn.net/nanaranran/article/details/19820425
下面先模拟一下这个错误:
SQL> select * from gw1;
ID NAME
---------- ----------
1 a
2 b
3 c
SQL> select * from gw2;
ID UPDATE_ID
---------- ----------
1 11
2 22
3 33
4 44
SQL> select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id;
ID UPDATE_ID
---------- ----------
1 11
2 22
3 33
SQL> update (select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id) tmp set tmp.id=tmp.update_id;
update (select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id) tmp set tmp.id=tmp.update_id
*
ERROR at line 1:
ORA-01779: cannot modify a column which maps to a non key-preserved table
产生这个错误的原因是因为gw2表的id不是唯一的,有可能gw1的一个id会对应多个gw2的id,这样就不知道怎么更新了。即使gw2的表中并不存在这样的记录。
解决方法:给gw2表的id列加上unique约束或设置为主键
SQL> alter table gw2 modify id unique;
Table altered.
SQL> update (select gw1.id,gw2.update_id from gw1,gw2 where gw1.id=gw2.id) tmp set tmp.id=tmp.update_id;
3 rows updated.
SQL> select * from gw1;
ID NAME
---------- ----------
11 a
22 b
33 c
如需转载,请注明出处:http://blog.csdn.net/nanaranran/article/details/19820425
相关文章推荐
- 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
- 解决错误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分析
- ORA-01779: cannot modify a column which maps to a non-key-preserved table
- ora-01779 non-key-preserved table错误及/*+ BYPASS_UJVC*/ 的使用技巧
- How to modify non-customizable entity in MS Dynamics CRM 4.0 (Add Product price column to Price List Item view)
- ORA-01445: Cannot Select ROWID from a Join View without a Key-Preserved Table
- java 中 Cannot make a static reference to the non-static 解决方法
- Cannot make a static reference to the non-static method的解决方法
- REP-20147 Cannot implement column link for this detail SQL query. Converting to group link.
- Cannot refer to a non-final variable inside an inner class defined in a different method
- Cannot attach additional subparts to non-multipart/*
- 解决ORA-00824: cannot set sga_target due to existing
- Bluemix RSA Private key cannot be used to encrypt
- Cannot refer to a non-final variable * inside an inner class defined in a different method错误问题
- Java中的报错:Cannot make a static reference to the non-static field
- Cannot refer to a non-final variable mylis inside an inner class defined in a different method
- Cannot refer to a non-final variable mylis inside an inner class defined in a different method
- 在视图或者子查询中查询rowid出错提示cannot select ROWID from a join view without a key-preserved table