Sql 如何更新与其他表联接的表中的列?

Sql 如何更新与其他表联接的表中的列?,sql,oracle,sql-update,Sql,Oracle,Sql Update,我想用其他表的引用更新表的两列。执行脚本时显示错误 错误:从命令第1行开始的错误: UPDATE wb_costing_work_items, sa_sales_documents, sa_sales_document_items SET cwi_price_per_hour = sdi_price, cwi_amount = sdi_price * cwi_hours WHERE cwi_lo_id = sad_lo_id AND sdi

我想用其他表的引用更新表的两列。执行脚本时显示错误

错误:从命令第1行开始的错误:

UPDATE wb_costing_work_items,
       sa_sales_documents,
       sa_sales_document_items
   SET cwi_price_per_hour = sdi_price,
       cwi_amount = sdi_price * cwi_hours
 WHERE cwi_lo_id = sad_lo_id
   AND sdi_sad_id = sad_id
   AND sdi_wit_id = cwi_wit_id
   AND cwi_id = 1650833
命令行错误:1列:28错误报告:SQL错误:ORA-00971: 缺少集合关键字 97100000-“缺少集合关键字”

SQL语句

UPDATE wb_costing_work_items cwi,
       sa_sales_documents sad, 
       sa_sales_document_items sdi
   SET cwi.cwi_price_per_hour = sdi.sdi_price,
       cwi.cwi_amount = sdi.sdi_price * cwi.cwi_hours
 WHERE cwi.cwi_lo_id = sad.sad_lo_id
   AND sdi.sdi_sad_id = sad.sad_id
   AND sdi.sdi_wit_id = cwi.cwi_wit_id
   AND cwi.cwi_id = 1650855

也许是这样的

注意,我不得不对哪个列属于哪个表进行一些猜测,因为您没有包含任何关于表定义方式的信息

所以很可能我没有正确理解,您需要根据实际的表结构调整查询

merge into wb_costing_work_items  
using 
(
    select cwi.pk_column,  -- don't know what the PK of the wb_costing_work_items is due to lack of information
           sdi.sdi_price,  -- don't know if this column really belong to this table
           sdi.sdi_price * cwi.cwi_hours as total-- again unsure about column names due to lack of information
    FROM wb_costing_work_items cwi
      JOIN sa_sales_documents sad ON sad.sad_lo_id = cwi.cwi_lo_id -- not sure about these, due to lack of information
      JOIN sa_sales_document_items sdi 
        ON sdi.sad_id = sad.sdi_sad_id     -- not sure about these, due to lack of information
       AND sdi.sdi_wit_id = cwi.cwi_wit_id -- not sure about these, due to lack of information

) t ON (t.pk_column = w.pk_column) -- not sure about this, due to lack of information
when matched then 
 update 
    set cwi_price_per_hour = t.sdi_price,
        cwi_amount = t.total;

也许是这样的

注意,我不得不对哪个列属于哪个表进行一些猜测,因为您没有包含任何关于表定义方式的信息

所以很可能我没有正确理解,您需要根据实际的表结构调整查询

merge into wb_costing_work_items  
using 
(
    select cwi.pk_column,  -- don't know what the PK of the wb_costing_work_items is due to lack of information
           sdi.sdi_price,  -- don't know if this column really belong to this table
           sdi.sdi_price * cwi.cwi_hours as total-- again unsure about column names due to lack of information
    FROM wb_costing_work_items cwi
      JOIN sa_sales_documents sad ON sad.sad_lo_id = cwi.cwi_lo_id -- not sure about these, due to lack of information
      JOIN sa_sales_document_items sdi 
        ON sdi.sad_id = sad.sdi_sad_id     -- not sure about these, due to lack of information
       AND sdi.sdi_wit_id = cwi.cwi_wit_id -- not sure about these, due to lack of information

) t ON (t.pk_column = w.pk_column) -- not sure about this, due to lack of information
when matched then 
 update 
    set cwi_price_per_hour = t.sdi_price,
        cwi_amount = t.total;

这肯定行得通

            UPDATE (SELECT cwi_price_per_hour,
                           sdi_price,
                           cwi_amount,
                           sdi_price,
                           cwi_hours
                      FROM wb_costing_work_items,
                           sa_sales_documents,
                           sa_sales_document_items
                     WHERE     cwi_lo_id = sad_lo_id
                           AND sdi_sad_id = sad_id
                           AND sdi_wit_id = cwi_wit_id
                           AND cwi_id = 1650833)
               SET cwi_price_per_hour = sdi_price, cwi_amount = sdi_price * cwi_hours

请为使用的表加上别名,并为列加上前缀,以便轻松阅读您的查询

这肯定行得通

            UPDATE (SELECT cwi_price_per_hour,
                           sdi_price,
                           cwi_amount,
                           sdi_price,
                           cwi_hours
                      FROM wb_costing_work_items,
                           sa_sales_documents,
                           sa_sales_document_items
                     WHERE     cwi_lo_id = sad_lo_id
                           AND sdi_sad_id = sad_id
                           AND sdi_wit_id = cwi_wit_id
                           AND cwi_id = 1650833)
               SET cwi_price_per_hour = sdi_price, cwi_amount = sdi_price * cwi_hours

请为使用的表加上别名,并为列加上前缀,以便轻松阅读您的查询

您要更新哪些表?我要更新表wb\U costing\u work\u项的两列值应来自其他表您要更新哪些表?我要更新表wb\u costing\u work\u项的两列值应来自其他表我尝试执行显示错误的语句行:12列:19错误报告:SQL错误:ORA-01779:无法修改映射到非键保留表01779的列。00000-“无法修改映射到非键保留表的列”*原因:试图插入或更新映射到非键保留表的联接视图的列*操作:直接修改基础基表。我尝试执行它显示的语句错误行:12列:19错误报告:SQL错误:ORA-01779:无法修改映射到非键保留表01779的列。00000-“无法修改映射到非键保留表的列”*原因:试图插入或更新映射到非键保留表的联接视图的列*操作:直接修改基础基表。此处别名“w”代表?此处别名“w”代表?