Oracle数据库:批量更新生成ORA-01779

ubbxdtey  于 2023-06-22  发布在  Oracle
关注(0)|答案(1)|浏览(96)

我尝试用Oracle数据库中另一个表的值批量更新表中所有硬编码的值。

    • 表请求**
  • 请求ID
  • 业务分配
  • 客户端ID
    • 表用户**
  • 用户id
  • 服务
    • 表lnk_request_user**
  • assignee_id(从用户表链接到user_id)
  • 请求ID
update
        (
        select req.SERVICE_ASSIGNED as OLD, users.service as NEW
            from REQUEST req, LNK_REQUEST_ASSIGNEE assignees, USER users
            where
                req.request_id = assignees.request_id
                and
                users.user_id = assignees.assignee_id
                and
                req.client_id=9999         
        ) request 
        set request.OLD = request.NEW;

Oracle返回:
SQL错误:ORA-01779:不能修改Map到非保留键表的列
什么意思如何修复我的查询?

hgncfbus

hgncfbus1#

我会像下面这样使用合并:

merge into REQUEST tgt
using (
  select req.request_id, users.service SERVICE_ASSIGNED
  from REQUEST req, LNK_REQUEST_ASSIGNEE assignees, USER users
  where req.request_id = assignees.request_id
    and users.user_id = assignees.assignee_id
    and req.client_id=9999           
) src
on (tgt.request_id=src.request_id)
when matched then update set
  tgt.SERVICE_ASSIGNED=src.SERVICE_ASSIGNED;

相关问题