Difference in select for update of ... in Oracle Database 10g and 11g
I found out that Oracle Database 10g and 11g treat the following PL/SQL block differently (I am using scott schema for convenience):
DECLARE
v_ename bonus.ename%TYPE;
BEGIN
SELECT b.ename
INTO v_ename开发者_JAVA技巧
FROM bonus b
JOIN emp e ON b.ename = e.ename
JOIN dept d ON d.deptno = e.deptno
WHERE b.ename = 'Scott'
FOR UPDATE OF b.ename;
END;
/
While in 10g (10.2) this code ends successfully (well NO_DATA_FOUND exception is raised but that is expected), in 11g (11.2) it raises exception "column ambiguously defined". And that is definitely not expected. It seems like it does not take into account table alias because I found out that when I change the column in FOR UPDATE OF e.empno (also does not work) to e.mgr (which is unique) it starts working. So is this some error in 11g? Any thoughts?
It's a bug in Oracle 11G. It was fixed in 11.2.0.2 version. It has been discussed in this thread: https://forums.oracle.com/forums/thread.jspa?threadID=2314477
There was a bug in Oracle 10g which was fixed in 11g where ORA-00918 column ambiguously defined was not being raised when it should have. I'm not sure if this applies to yours though because you have specified all aliases.
Is there a foreign-key relationship enforced on bonus.ename -> emp.ename?
Have you tried using the non-ANSI join syntax, e.g.:
SELECT b.ename
INTO v_ename
FROM bonus b, emp e, dept d
WHERE b.ename = 'Scott'
AND b.ename = e.ename
AND d.deptno = e.deptno
FOR UPDATE OF b.ename;
精彩评论