Oracle数据库sql语句

程序小海 2013-12-23 01:33:43
 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“呢?
...全文
128 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序小海 2013-12-23
  • 打赏
  • 举报
回复
sql语句 后面加上: where s.pk_tw_user_id = (select distinct u.tu_user_bh from tb_userinfo u where u.agentno like'9___' and s.isactive='Y' and u.isactive='Y' and s.pk_tw_user_id=u.tu_user_bh)
_拙计 2013-12-23
  • 打赏
  • 举报
回复
引用 6 楼 stone1314 的回复:
引用 5 楼 lu010610 的回复:
原来是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')
这样应该可行吧
程序小海 2013-12-23
  • 打赏
  • 举报
回复
引用 5 楼 lu010610 的回复:
原来是oracle的 那你把条件补齐应该可以吧
条件没问题
_拙计 2013-12-23
  • 打赏
  • 举报
回复
原来是oracle的 那你把条件补齐应该可以吧
_拙计 2013-12-23
  • 打赏
  • 举报
回复
你这样条件不太多 而且效率也低 试试这样的
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'
liujie2300 2013-12-23
  • 打赏
  • 举报
回复
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表主键去了,
songyangbingbing 2013-12-23
  • 打赏
  • 举报
回复
子查询的where条件比 update 的where 条件多 不是有b.agentno like'9___' and a.isactive='Y' and b.isactive='Y' 第一个回复 因为没细看 sorry
songyangbingbing 2013-12-23
  • 打赏
  • 举报
回复
因为这列不允许为空值吧

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧