from:http://www.raincat.net/blog/showlog.asp?cat_id=6&log_id=428
示例:
SQL> update tb_test_log a
2 set game_deal_log_id = (select game_deal_log_id
3 from test b
4 where a.table_id = b.table_id);
2 set game_deal_log_id = (select game_deal_log_id
3 from test b
4 where a.table_id = b.table_id);
上述多表联合更新时,有时会报“ORA-01407: cannot update to null”错误,原因系存在表间关联不到的记录(null)。
解决方法:
SQL> update tb_test_log a
2 set game_deal_log_id = (select game_deal_log_id
3 from test b
4 where a.table_id = b.table_id)
5 where exists (select 1 from test b where a.table_id=b.table_id);
2 set game_deal_log_id = (select game_deal_log_id
3 from test b
4 where a.table_id = b.table_id)
5 where exists (select 1 from test b where a.table_id=b.table_id);

本文介绍了一种在Oracle数据库中更新表时避免出现'ORA-01407: cannot update to null'错误的方法。通过使用EXISTS子句确保只有在目标表中有匹配记录时才进行更新操作。
702

被折叠的 条评论
为什么被折叠?



