【问题标题】:How to update when subquery returns multiple rows (with cursor)子查询返回多行时如何更新(带游标)
【发布时间】:2016-02-06 14:05:38
【问题描述】:
update tac_master
   set msg = (select 'Yes,this is a 4G supportive handset.Marketing Name'||MKT_NAME||' of LTE:1800 Manufacturer#'||manufacturer 
              from tac_master)
where lte_1800='Yes';

附表数据及结构Table sample

【问题讨论】:

  • 为什么要选择?你想做什么?在我看来,你只是想要:update tac_master set msg = 'Yes,this is a 4G supportive handset.Marketing Name'||MKT_NAME||' of LTE:1800 Manufacturer#'||manufacturer where lte_1800='Yes';,但根据给出的信息,这是不可能回答的

标签: sql oracle sql-update


【解决方案1】:

至于您指定的代码,只需将子查询更改为 value,因为您正在使用常量值更新它 - 您无需再次查询它来获取 mkt_name 和制造商值,因为它们在 update 语句中可用:

update tac_master
set msg = 'Yes,this is a 4G supportive handset.Marketing Name'||MKT_NAME||' of LTE:1800 Manufacturer#'||manufacturer
where lte_1800='Yes';

关于在子查询返回多个值时更新行的一般问题 - 你不能,这就是你得到这个错误的原因,Oracle 必须知道当前必须修改哪个值,并按照你的方式进行'没有定义它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多