Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> MERGE statement ON (cond) question

MERGE statement ON (cond) question

From: rt lange <whiteywidow_at_yahoo.com>
Date: Tue, 18 May 2004 23:51:00 GMT
Message-ID: <Xns94EDCBB7542F0whiteywidowyahoocom@216.77.188.18>


I'm wondering what exactly happens when the condition gets evaluated.

It makes sense when I think of it as a (equi)join condition i.e.:

    	MERGE INTO copy_emp c
    	    	USING employees e
    	    	ON (e.employee_id = c.employee_id)
    	   etc.

So when the condition is true (the ids match) that particular row from the source table (e) is used to update columns of the the corresponding (matching) row from the target table (c).

But the example in my book is different:

    	MERGE INTO copy_emp c
    	    	USING employees e
    	    	ON (e.employee_id = 100)
    	  etc.

So when the condition is true that particular row from the source table is used to update ... ?? - there's no corresponding row in the target table that is specified. Does it automatically check if c.employee_id = 100 and then use that row? What if the column names don't match?

Doesn't the condition have to contain columns from both tables? If it doesn't what would happen with say (e.employee_id > 200)? Can the condition contain anything a WHERE clause could? Is ON (e.empoyee_id = 100) equivalent to ON (c.employee_id = 100)?

All of the examples I've seen online contain join conditions. Can I presume that's the way MERGE should be used 99% of the time?

The SQL Reference doesn't really help. All it says is:

"For each row in the target table for which the search condition is true, Oracle Database updates the row with corresponding data from the source table. If the condition is not true for any rows, then the database inserts into the target table based on the corresponding source table row." Received on Tue May 18 2004 - 18:51:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US