ORA-01407: cannot update to null 错误解决
来源:互联网 发布:centos wingide 安装 编辑:程序博客网 时间:2024/06/06 10:57
ORA-01407: cannot update to null 错误解决
在更新客户数据时 出现ORA-01407错误
SQL> select table_id,game_deal_log_id from tb_test_log;
TABLE_ID GAME_DEAL_LOG_ID
---------- ----------------
G 0
10001 4923601
AA 4923676
BB 4923672
CC 4923677
DD 4923674
FF 4923673
GG 4923671
HH 2616668
II 4923668
C 0
D 0
E 0
F 0
14 rows selected
SQL> select * from test;
GAME_DEAL_LOG_ID TABLE_ID
---------------- ----------
4661667 10001
4661556 AA
4661558 BB
4661559 CC
4661553 DD
4661552 FF
4661555 GG
2616668 HH
4661557 II
9 rows selected
SQL>
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);
update tb_adjustment_handledeal_log a
set game_deal_log_id = (select game_deal_log_id
from test b
here a.table_id = b.table_id)
ORA-01407: cannot update ("TEST"."TB_TEST_LOG"."GAME_DEAL_LOG_ID") to NULL
这是因为上面sql运行时 会更新所有game_deal_log_id字段 下面我删除不相等的table_id
QL> delete from tb_test_log where table_id in ('C','D','E','F','G');
5 rows deleted
SQL>
SQL> update tb_test_log a
2 set game_deal_log_id = (select game_deal_log_id
from test b
4 where a.table_id = b.table_id);
9 rows updated
更新成功 这个sql就只能保证两边数据记录一致 才能更新成功
SQL> select table_id,game_deal_log_id from tb_test_log;
TABLE_ID GAME_DEAL_LOG_ID
---------- ----------------
10001 4661667
AA 4661556
BB 4661558
CC 4661559
DD 4661553
FF 4661552
GG 4661555
HH 2616668
II 4661557
9 rows selected
SQL> rollback;
Rollback complete
SQL>
所以上面sql还是写的有问题,没有真正关联到相等的table_id,采取如下写法就是正确的写法
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);
9 rows updated
SQL> select table_id,game_deal_log_id from tb_test_log;
TABLE_ID GAME_DEAL_LOG_ID
---------- ----------------
G 0
10001 4661667
AA 4661556
BB 4661558
CC 4661559
DD 4661553
FF 4661552
GG 4661555
HH 2616668
II 4661557
C 0
D 0
E 0
F 0
14 rows selected
- ORA-01407: cannot update to null 错误解决
- ORA-01407: cannot update错误
- java hibernate 中"node to traverse cannot be null"错误解决
- java hibernate 中"node to traverse cannot be null"错误解决
- java hibernate 中"node to traverse cannot be null"错误解决
- 解决错误ORA-01779: cannot modify a column which maps to a non-key-preserved table
- ORA-01407 错误解决
- 错误:java.lang.IllegalArgumentException: node to traverse cannot be null!
- 使用hibernate出现node to traverse cannot be null错误
- hibernate错误之node to traverse cannot be null
- 【SSH错误整理】node to traverse cannot be null!
- 异常:node to traverse cannot be null! 的错误分析
- java hibernate 中"nodeto traverse cannot be null"错误解决
- TypeError: Cannot read property 'style' of null 错误解决
- Uncaught TypeError: Cannot set property ' ' of null 错误解决
- ORA-04092: cannot COMMIT in a trigger错误的解决
- Unable to locate appropriate constructor on class, node to traverse cannot be null 错误解决方案
- interbase "Cannot attach to password database"错误解决一例
- HTML常用标签
- 80 咱们变老了
- 键盘妙用 史上最全
- 菜单(不完全版)
- hdu acm1013
- ORA-01407: cannot update to null 错误解决
- struts1 和 struts2中的validate
- 胆小的借口
- VC个性化窗口界面设计
- 向雨林木风 linux叫声好
- 教你使用dos命令扫描开放端口
- Code::Blocks 满足你任何苛刻的要求的C/C++ IDE
- 用CImage类来显示PNG、JPG等图片
- php 技术内幕学习1