update emp a
set comm=(
select decode(LOC,'NEW YORK',500,'DALLAS',600,'CHICAGO',700,800)
from dept b
where a.deptno=b.deptno
)
where exists(
select decode(LOC,'NEW YORK',500,'DALLAS',600,'CHICAGO',700,800)
from dept b
where a.deptno=b.deptno
);
如你所见,操作是为了更新emp表的comm列,当LOC为NEW YORK时,comm为500;
当LOC为DALLAS时,comm为600;
当LOC为CHICAGO时,comm为700;
当LOC为其他值时,comm为800.
where exists(
select decode(LOC,'NEW YORK',500,'DALLAS',600,'CHICAGO',700,800)
from dept b
where a.deptno=b.deptno
)
为存在性判断,更新操作时可以使用,当然有时可以不用则省略
decode 百度百科地址连接
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25538895/viewspace-706816/,如需转载,请注明出处,否则将追究法律责任。