带有联接的Oracle Update查询 [英] Oracle Update query with joins

查看:62
本文介绍了带有联接的Oracle Update查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道update子句不适用于Oracle中的联接.

I do know update clause doesn't work with joins in Oracle.

update table1 Pr
set code = (select t2.class_attr_value from table2 t2
where  class_attr_name = 'sample' and Pr.epcclass_id = t2.epcclass_id)

如果有人可以帮助我修改查询,使我不会收到未正确结束的SQL Command错误,我将不胜感激.

I would be thankful if someone can help me modify my query so that I don't get the error of SQL Command not ended properly.

推荐答案

您的查询对我来说似乎还可以,我刚刚添加了表别名.您的查询将更新表1中的所有记录.您遇到什么错误...?

Your Query seems okay to me I just added Table Alias. Your query will update all records in table1. What error you are getting...??

建议

a)除非您要更新所有记录,否则请在查询中添加where子句,以避免更新所有记录...

a) Unless it's the intent that you want to update all records, add a where clause in the query to avoid updating all records...

b)如果要获取(ORA-01427:单行子查询返回多行),则意味着相关子查询(在方括号内)缺少某种条件,因此每个epcclass_id仅读取1行.

b) If you are getting (ORA-01427: single-row subquery returns more than one row) then means corelated sub query (within brackets) is missing some condition to make it fetch only 1 row per epcclass_id.

update table1 Pr
set Pr.code = (select t2.class_attr_value 
               from table2 t2 
               where  t2.class_attr_name = 'sample' 
               and t2.epclass_id = Pr.epcclass_id 
              );

这篇关于带有联接的Oracle Update查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆