Oracle issue : ------------------ ORA-01779: cannot modify a column which maps to a non key-preserved table Reason : update ( select ur.sysadmin FROM user_role ur INNER JOIN user_profile up ON up.user_id = ur.user_id INNER JOIN role r ON r.role_id = ur.role_id WHERE ur.sysadmin = 1 and ( up.sysadmin = 0 or r.sysadmin = 0 )) t SET t.sysadmin = 0; Because inline view returns 0 rows and oracle could figure out records to be updated. Solution : update user_role usr set usr.sysadmin = 0 where exists ( select ur.* FROM user_role ur INNER JOIN user_profile up ON up.user_id = ur.user_id INNER JOIN role r ON r.role_id = ur.role_id WHERE ur.sysadmin = 1 and ( up.sysadmin = 0 or r.sysadmin = 0 )); We can also use merge statement to update rows in join merge INTO resource_master c USING resource_master p ON (p.resource_id = c.parent_id) WHEN matched THEN UPDATE SET c.active = 0;
Sunday, November 18, 2012
ORA-01779: cannot modify a column which maps to a non key-preserved table
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment