1、
update employee a set a.dept_id=(
 select decode(dept_id,null,'0',dept_id) from
   ( 
      select dept_id,rownum as rid from nm_dept_user 
       where user_id=(select user_id from nm_user where re=a.emp_id)
   )
  where rid=1
)
where companyflag='0' and dept_id not in( select dept_id from nm_dept ) 
2、
update employee a set a.dept_id=
   (
       select decode(dept_id,null,'0',dept_id) from nm_dept_user 
       where user_id=(select user_id from nm_user where re=a.emp_id)
         and rownum=1
   )
where companyflag='0' and dept_id not in( select dept_id from nm_dept ) 

解决方案 »

  1.   

    没有什么区别,一个是ROWNUM 直接使用
    一个使用ROWNUM的别名来用
      

  2.   

    对于你这两个语句没什么区别,但是如果1句内层查询加上排序order by之后,两句SQL就不一样了!有可能造成你两句SQL结果不一样!
      

  3.   

    这个跟你情况差不多.
    http://topic.csdn.net/u/20100719/13/b85e77e4-b916-4bac-9b91-70904bef918b.html