ORA-01407: cannot update错误
2017-10-20 15:05
344 查看
前提:有两个表
1、学生表:student(id,name,t_id); t_id是非空的
2、教师表:teacher(id,name)
需求:把学生表中t_id都更新成teacher表的name
sql语句:
update student t
set t.t_id=(select s.name from teacher s where s.id=t.t_id)
报ORA-01407错。
解决方法:
update student t
set t.t_id=(select s.name from teacher s where s.id=t.t_id)
where exists(select 1 from teacher s where s.id=t.t_id)
说明:
如果不想报ORA-01407这个错误,有两种办法
1、student,teacher两张表的记录要完全一样
2、要update的表记录要比对照表的记录少
不然update的时候在最后就要加一个 where exists 语句,这个和merge的用法很像,当然这只是一个特例,对于没有指定not null的列,普通的update是完全没有问题的
参考链接:
http://blog.sina.com.cn/s/blog_4a5eb9980101bt8x.html
1、学生表:student(id,name,t_id); t_id是非空的
2、教师表:teacher(id,name)
需求:把学生表中t_id都更新成teacher表的name
sql语句:
update student t
set t.t_id=(select s.name from teacher s where s.id=t.t_id)
报ORA-01407错。
解决方法:
update student t
set t.t_id=(select s.name from teacher s where s.id=t.t_id)
where exists(select 1 from teacher s where s.id=t.t_id)
说明:
如果不想报ORA-01407这个错误,有两种办法
1、student,teacher两张表的记录要完全一样
2、要update的表记录要比对照表的记录少
不然update的时候在最后就要加一个 where exists 语句,这个和merge的用法很像,当然这只是一个特例,对于没有指定not null的列,普通的update是完全没有问题的
参考链接:
http://blog.sina.com.cn/s/blog_4a5eb9980101bt8x.html
相关文章推荐
- ORA-01407: cannot update to null 错误解决
- 对存在如两张表连接的视图进行UPDATE时产生ORA-1779错误
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误
- org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-01017: invalid username/password; logon denied 错误解决
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- [oracle][免安装Oracle客户端] ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- 错误 ORA-01102: cannot mount database in EXCLUSIVE mode 的处理方法
- 错误 ORA-01102: cannot mount database in EXCLUSIVE mode 的处理方法
- oracle 启动时出现ORA-01157: cannot identify/lock data和ORA-01110: data file 错误
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- MySQL外键 Cannot add or update a child row错误的实例解释
- 使用Update...returning...into为什么会出现ORA-01036,ORA-24369错误 <收藏>
- wince 系统error C2471: cannot update program database 错误解决办法。
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- 错误整理: ORA-12705: Cannot access NLS data files or invalid environment specified
- ORA-01407 错误解决
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误
- ORA-12705: Cannot access NLS data files or invalid environment specified 错误