使用两个表进行更新,串联
我需要创建此查询中涉及的两个表,并且我不确定如何连接这两个表以进行更新。
我有一个 ITEM 和 CONSUMER_ITEMS 表。 ITEM 表中的每个项目都有一个不同的代码和一个 UPC 代码。 我需要将一个字符串与 ITEM.UPC_CODE 连接到 CONSUMER_ITEMS.NEW_ITEM_CODE,其中 CONSUMER_ITEMS.ITEM_CODE =(ITEM.ITEM_CODES 的特定列表)
我将如何更新 CONSUMER_ITEMS.NEW_ITEM_CODE 字段?
它本质上等于“字符串”|| ITEM.UPC 但如何引用 CONSUMER_ITEMS.ITEM_CODE 使其等于要更新的 ITEM_CODES 列表中的特定 ITEM_CODE。
I have two tables involved in this query I need to create, and I'm not exactly sure how to join these two tables in order to update.
I have a ITEM and CONSUMER_ITEMS table. The ITEM table has a distinct code for each item and a UPC code. I need to concatenate a string with the ITEM.UPC_CODE to CONSUMER_ITEMS.NEW_ITEM_CODE where CONSUMER_ITEMS.ITEM_CODE = (Specific list of ITEM.ITEM_CODES)
How would I go about updating the CONSUMER_ITEMS.NEW_ITEM_CODE Field?
It would essentially be equal to 'string' || ITEM.UPC but how do I reference the CONSUMER_ITEMS.ITEM_CODE to be equal to the specific ITEM_CODE in the list of ITEM_CODES to be updated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来像您想要的:
或者,假设表之间存在外键关系,并且 Consumer_items 有主键,这应该有效:
编辑:添加了 WHERE 子句
Sounds like you want:
Alternatively, assuming there is a foreign key relationship between the tables and that consumer_items has a primary key, this should work:
EDIT: Added WHERE clauses
i.ITEM_CODE、i.UPC的列表是这样的:
第一列是ITEM CODES,第二列是UPC。 这是在 ITEMS 表上。
CONSUMER_ITEMS 表本质上也有一个 CONSUMER_ITEMS.ITEM_CODE。 这就是 LINK,但它还有一个名为 CONSUMER_ITEMS.NEW_ITEM_CODE 的字段。 我们希望使用上面列表中相应 ITEM_CODE 中的 UPC 填充 NEW_ITEM_CODE,并连接“字符串” || 上面的 UPC 代码。
我们如何生成该列表:
这会生成上面的 ITEM_CODE、UPC 列表。 我需要更新与上面这些代码匹配的 CONSUMER_ITEMS。 具体来说,我需要更新其 NEW_ITEM_CODE 字段(该字段为空),并使用与 STRING 连接的相应 UPC。
The list of i.ITEM_CODE, i.UPC is this:
The first column is ITEM CODES, Second Column is UPCs. This is on the ITEMS table.
The CONSUMER_ITEMS table essentially has a CONSUMER_ITEMS.ITEM_CODE as well. That's the LINK, but it also has a field called CONSUMER_ITEMS.NEW_ITEM_CODE. We want to fill the NEW_ITEM_CODE with the UPC from the corresponding ITEM_CODE in the list above with a concatentation of 'string' || UPC CODE FROM ABOVE.
How we generate that list is:
This generates the ITEM_CODE, UPC list above. I need to update the CONSUMER_ITEMS that MATCH those codes above. Specifically, I need to update their NEW_ITEM_CODE fields, which are null, with the corresponding UPC concatenated with a STRING.
是的,这看起来不错,但 item.item_code = ci.item_code 不起作用,因为:
这是与那些经常用于更新 CONSUMER_ITEMS 的代码关联的代码和 UPC 的不同列表。
似乎不起作用
Right, that looks great but the item.item_code = ci.item_code doesn't work because:
This is the distinct list of CODES and UPC associated with those codes that much be used to update the CONSUMER_ITEMS.
doesn't seem to work
/*+ BYPASS_UJVC */
如果您收到以下 Oracle 错误,请使用此提示 - ORA-01779: 无法修改映射到非键保留表的列
/*+ BYPASS_UJVC */
use this hint if you are getting the following oracle error- ORA-01779: cannot modify a column which maps to a non key-preserved table