Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle MERGE statement ON clause error

Posted on 2004-08-20
4
Medium Priority
?
669 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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