?
Solved

Oracle MERGE statement ON clause error

Posted on 2004-08-20
4
Medium Priority
?
667 Views
Last Modified: 2008-01-09
Example code: **************************************

merge into genericitem x
using (select distinct changedocid, changedoctype from effectivity) y
on (x.itemid = y.changedocid and x.itemtypecd = y.changedoctype)
when matched then update set x.subtypecd = null
when not matched then insert (x.itemid, x.itemtypecd, x.subtypecd)
values (y.changedocid, y.changedoctype, null)

(itemid + itemtypecd) = the primaryKey for the genericitem table
(itemid + itemtypecd) = the primaryKey for the genericitem table

Problem: ******************************************

I get the Oracle error:
   ORA-00904: "X"."ITEMTYPECD": invalid identifier

generated from the clause:
    on (x.itemid = y.changedocid and x.itemtypecd = y.changedoctype)  

Question(s): ****************************************

1. Can I use multiple join operators?
2. If so, why am I getting the error?
3. I want to use this Merge statement for many tables that all require multiple join operators in the ON clause.  How can I make this work?

Thanks
MarkHensley
markjhensley@msn.com

0
Comment
Question by:MarkHensley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
geotiger earned 1500 total points
ID: 11855547

Is itemtypecd somehow related to subtypecd (composite key from subtypecd or there is integrity constraint on it)?  You can not update key that is used in ON clause. This is an undocumented feature .

Please see it more at this link:

http://asktom.oracle.com/pls/ask/f?p=4950:8:6906283133203542202::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:5318183934935,

GT

0
 

Author Comment

by:MarkHensley
ID: 11856373
subtypecd is part of a UK on the genericitem table, the UK is defined as itemid,itemtypecd,subtypecd

There are only three columns in the entire table, so if I can't update any of the three then whant should the syntax of the following be?

when matched then update set x.subtypecd = null

When I try and onit the "when matched" clause it throws an error and there are no other columns to update.
0
 
LVL 12

Expert Comment

by:geotiger
ID: 11856423
You might want to avoid MERGE INTO completely since you do not want to update it when matched. You then use the insert into as the following


Insert into genericitem x
select distinct changedocid, changedoctype, null
from effectivity
where x.itemid != changedocid and x.itemtypecd != changedoctype);

GT
0
 
LVL 12

Expert Comment

by:geotiger
ID: 11856449
I do not know whether this is going to work. You can try it since you have the tables:

merge into genericitem x
using (select distinct changedocid, changedoctype from effectivity) y
on (x.itemid = y.changedocid and x.itemtypecd = y.changedoctype)
when matched then NULL
when not matched then insert (x.itemid, x.itemtypecd, x.subtypecd)
values (y.changedocid, y.changedoctype, null)
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question