读书人

Oracle数据库sql语句,该怎么解决

发布时间: 2013-12-26 00:35:35 作者: rapoo

Oracle数据库sql语句

 update  tb_shop a set a.pk_tw_user_id= (select    b.agentno    from  
tb_userinfo b where b.agentno like'9___' and a.isactive='Y' and b.isactive='Y' and a.pk_tw_user_id=b.tu_user_bh )
where exists (select 1 from tb_userinfo b where a.pk_tw_user_id=b.tu_user_bh);


为什么 还是报错”出现ORA-01407: 无法更新 ("SCOTT"."tb_shop "."pk_tw_user_id") 为 NULL“呢?
[解决办法]
子查询的where条件比 update 的where 条件多 不是有b.agentno like'9___' and a.isactive='Y' and b.isactive='Y' 第一个回复 因为没细看 sorry
[解决办法]
select b.agentno from tb_userinfo b, tb_shop a where b.agentno like'9___' and a.isactive='Y' and b.isactive='Y' and a.pk_tw_user_id=b.tu_user_bh 这个条件关联出来的数据有空值
但是
a..pk_tw_user_id 应该是主键不能为空!

1.解决办法 要不核查B表查出来的数据为啥为空,看是否是错误数据
2.把A表主键去了,
[解决办法]
你这样条件不太多 而且效率也低 试试这样的
update a
set a.pk_tw_user_id = b.agentno from tb_shop a, tb_userinfo b
where a.pk_tw_user_id = b.tu_user_bh
and b.agentno like '9___'
and a.isactive = 'Y'
and b.isactive = 'Y'

[解决办法]
原来是oracle的 那你把条件补齐应该可以吧
[解决办法]
引用:
Quote: 引用:

原来是oracle的 那你把条件补齐应该可以吧
条件没问题

update tb_shop a
set a.pk_tw_user_id =
(select b.agentno
from tb_userinfo b
where a.pk_tw_user_id = b.tu_user_bh)
where a.isactive = 'Y' and exists (select 1
from tb_userinfo b
where a.pk_tw_user_id = b.tu_user_bh
and b.agentno like '9___'
and b.isactive = 'Y')

这样应该可行吧

读书人网 >oracle

热点推荐