日期:2014-05-17  浏览次数:20828 次

update的where语句后不带关联条件就会报错吗
直接执行则会报错ORA-01407如下:
SQL> update t_rm_subversioninfo a
  2  set a.verid=(select t.pro_id from t_hwz t where t.pro_name=a.projectname )
  3  ;
 
update t_rm_subversioninfo a
set a.verid=(select t.pro_id from t_hwz t where t.pro_name=a.projectname )
 
ORA-01407: 无法更新 ("CCRM"."T_RM_SUBVERSIONINFO"."VERID") 为 NULL

但是已经确认了这样关联查询出来的结果是没有空值的:select t.pro_id from t_rm_subversioninfo a,
t_hwz t where t.pro_name=a.projectname

将两张表在where后面做了exists关联,问题是解决了,可是为什么会这样,还是搞不清楚,麻烦大神们明示,多谢!
SQL> 
SQL> update t_rm_subversioninfo a
  2  set a.verid=(select t.pro_id from t_hwz t where t.pro_name=a.projectname )
  3  where exists (select 1 from t_hwz t where t.pro_name=a.projectname);
 
34 rows updated
 
SQL> 
update? ORA-01407 空值

------解决方案--------------------
你不带where条件就是全表更新!!!!!!!!!!!!
t_rm_subversioninfo  中 verid 不在  select t.pro_id from t_hwz t where t.pro_name=a.projectname 就会更新为null值啊,很好理解吧。。