views:

270

answers:

1

Hi, 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
    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?

A: 

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;
Jeffrey Kemp
I tried and non-ANSI syntax works as expected. So it seems that they fixed the bug you mentioned but introduced another. :-)
sax