MERGE INTO and CROSS JOIN

Hello Guys,
I have a bit of trouble understanding the MERGE I have written here.
All the code executes without errors. As far as I see,
the below MERGE SELECT is a Cartesian product/cross join and I remember that is not
good. The ON (join condition) seems to be only for the merge into table (T_CLAIMS_BB) and
the table that comes from the select (d).
merge into T_CLAIMS_BB t
using
SELECT sch_vt.SCH#,vert.CNO,vers.SubCNo,regv.ReturnNo,regv.SndReturnNo,sch_vt.MainProd,sch_vt.Prod
FROM mainschema.TCONTRACT vert, mainschema.TVERSCONTRACT vers, commonschema.VC_REGVEREINB regv, myschema.T_CLAIMS_VT sch_vt
) d
ON (
t.sch# = d.sch# AND
SUBSTR(UPPER(t.BOOKINGTEXT),1,2) = d.SndReturnNo AND d.SubCNo IS NULL
) -- Join
when matched then
update
set t.CNO = 'a',
t.ReturnNo = 'a',
t.MainProd = 'b',
t.Prod = 'c';
I wonder now, what is the advantage of using MERGE in my case - if there is one.
Finally I want to demonstrate how the whole thing would look without a MERGE:
SELECT vers.* FROM TVERSCONTRACT vers
LEFT OUTER JOIN myschema.T_CLAIMS_BB sch ON sch.SubCNo = vers.SubCNo
LEFT OUTER JOIN commonschema.VC_REGVEREINB regv ON sch.SCH# = regv.SCH# AND SUBSTR(UPPER(sch.BUCHTEXT),1,2) = regv.SndReturnNo AND sch.SubCNo IS NULL
LEFT OUTER JOIN myschema.T_CLAIMS_VT sch_vt ON sch.SCH# = sch_vt.SCH#

Hi,
metalray wrote:
Hello Guys,
I have a bit of trouble understanding the MERGE I have written here.
All the code executes without errors. As far as I see,
the below MERGE SELECT is a Cartesian product/cross join and I remember that is not
good.Cross joins are good for some purposes. In practice, they're useful in only 1 or 2 queries out of every 1000.
Using the old join notation, it was very easy to get a cross join by mistake. Given how rarely cross joins are needed, the vast majority of cross joins (using old notation) were not good, but that was the fault of the programmers and the notation, not an indication that cross join itself was bad.
The ON (join condition) seems to be only for the merge into table (T_CLAIMS_BB) and
the table that comes from the select (d).Exactly!
You can have separate ON conditions inside the USING sub-query, if you need them.
>
merge into T_CLAIMS_BB t
using
SELECT sch_vt.SCH#,vert.CNO,vers.SubCNo,regv.ReturnNo,regv.SndReturnNo,sch_vt.MainProd,sch_vt.Prod
FROM mainschema.TCONTRACT vert, mainschema.TVERSCONTRACT vers, commonschema.VC_REGVEREINB regv, myschema.T_CLAIMS_VT sch_vt
) d
ON (
t.sch# = d.sch# AND
SUBSTR(UPPER(t.BOOKINGTEXT),1,2) = d.SndReturnNo AND d.SubCNo IS NULL
) -- Join
when matched then
update
set t.CNO = 'a',
t.ReturnNo = 'a',
t.MainProd = 'b',
t.Prod = 'c';
I wonder now, what is the advantage of using MERGE in my case - if there is one.I don't see any advantage, but I suspect the statement, as written, is not doing what it's supposed to. If someone made the mistake of using MERGE when UPDATE would be better, that might be the least of the mistakes in this statement.
Finally I want to demonstrate how the whole thing would look without a MERGE:It looks like the MERGE statement above is equivalent to:
UPDATE     t_claims_bb
SET     cno          = 'a'
,     returnno     = 'a'
,     mainprod     = 'b'
,     prod          = 'c'
WHERE     UPPER (SUBSTR (bookingtext, 1, 2)) IN
          SELECT  returnno
          FROM     commonschema.vc_regvereinb
AND     EXISTS
          SELECT  1
          FROM     mainschema.tverscontract
          WHERE     subcno     IS NULL
AND     EXISTS
          SELECT     1
          FROM     mainschema.tcontract
AND     EXISTS
          SELECT     1
          FROM     myschema.t_claims_vt
;Again, I suspect that the MERGE state,ment above is not doing what it was meant to do, or may coinncidentally be getting the right results on a small sample set. Many of the tables named in the USING clause of the MERGE statement do'nt seem to have much of a role in this problem.
SELECT vers.* FROM TVERSCONTRACT vers
LEFT OUTER JOIN myschema.T_CLAIMS_BB sch ON sch.SubCNo = vers.SubCNo
LEFT OUTER JOIN commonschema.VC_REGVEREINB regv ON sch.SCH# = regv.SCH# AND SUBSTR(UPPER(sch.BUCHTEXT),1,2) = regv.SndReturnNo AND sch.SubCNo IS NULL
LEFT OUTER JOIN myschema.T_CLAIMS_VT sch_vt ON sch.SCH# = sch_vt.SCH#What is this query? Perhaps you meant to have something like this in the USING clause of the MERGE.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
The sample data should show what the tables are like before the MERGE (or UPDATE), and the results will be the contents of the changed table after the MERGE.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using.

Similar Messages

  • Non equijoin and cross join

    I tried learning about nonequi join and cross join.
    When I try non equi join "select * from emp,dept;"...I am getting total of 60 rows.
    when I try cross join "select * from emp cross join dept"...I am getting same count(60 rows) and same output.
    Can anypone please give me the exact difference between the above joins.
    Which cases they are used.
    Thanks

    Hi,
    user11048416 wrote:
    I tried learning about nonequi join and cross join.
    When I try non equi join "select * from emp,dept;"...I am getting total of 60 rows.
    when I try cross join "select * from emp cross join dept"...I am getting same count(60 rows) and same output.
    Can anypone please give me the exact difference between the above joins.Those two are exactly the same. The first one is Oracle's older notation, the other second (using the keywords CROSS JOIN) is ANSI syntax, which Oracle started supporting in version 9.
    Which cases they are used.By far, the most common occurrence of cross joins is when someone forgets to add join conditions in the older syntax. That's one reason why ANSI syntax is better.
    There are real uses, but they are not very common, and getting rarer.
    If one of the tables (usually a result set, not a full table) has only one row, it's a way to add the columns of that "table" to another result set.
    Cross-joins are also used for partitioned outer joins (where you want one row for each combination of attributes, whether or not it actually occurs in the data) and unpivots displaying several columns from the same row as if they were one column on several rows). In Oracle 11, there are cleaner ways for doing both of these.

  • Difference between Innner Join and Cross Join

    Dear all,
    select * from tbl1 inner join tbl2 on tbl1.id =tbl2.id
    select * from tbl1 cross join tbl2 
    Works same what is the logical difference between this two statements??
    Dilip Patil..

    INNER Join returns the rows from  both tables which has satisfied matching condition.
    In
    CROSS Join, each record from tbl1 is matched with tbl2. Result would be Number Of rows in tbl1 X Number of rows in tbl2.
    Note: If you provide where condition in CROSS JOIN, it will give you same result as your first INNER JOIN query
    select * from tbl1 cross join tbl2 
    where tbl1.id =tbl2.id
    -Vaibhav Chaudhari

  • I have 20,00 images in my iphoto they have all been merged into one event. How do I restore them to the original events and dates? them

    I have 20,00 images in my iphoto they have all been merged into one event. How do I restore them to the original events and dates?

    Load the backup from before this happened
    LN

  • I have 2 ipods,one for music and the other for old time radio shows.Each had their own file.My computer crashed and I had to buy a new one.Now both ipod files are merged into one.How do I seperate them.

    I have 2 ipods,one for music and the other for old time radio shows.Each had their own file.My computer crashed and I had to buy a new one.Now both ipod files are merged into one.How do I seperate them on the computer?

    Hi Craig
    Unfortunately, in your case, there isn't really a way to separate them as far as I can think.
    You could try restoring from a backup, and choosing an older backup perhaps
    Cheers

  • I have recently transferred data from my old Mac to my new one. The result was good, but I have 2 users now, whose data I want to merge into 1 single user, so to avoid having to switch from one user to the other to view and use certain files. How to do it

    I have recently transferred data from my old Mac to my new one. The result was good, but I have 2 users now, whose data I want to merge into 1 single user, so to avoid having to switch from one user to the other to view and use certain files. How to do it?

    Here's an easy way:
    Pick the user that you want to eliminate (making sure that the remaining user has administrator privileges) and move all of the data that you want to keep into the Shared folder. Reboot or log out and login to the user you want to keep. Copy all the data from the Shared folder into your account - placing it neatly in folders (Documents, Music, Movies, etc.).
    Once the data is moved, log into the account you want to delete just once more to make certain that you've grabbed all the data you want to keep. Log out and log back into your admin account and go to System Preferences>Users & Groups and delete the 'old' user.
    That should do it.
    Clinton

  • Acrobat 9 - we are unable to merge word and excel files into a pdf.

    Acrobat 9 - we are unable to merge word and excel files into
    a pdf. Any advice?

    To be expected if you are working in a contemporary OS and contemporary MS Office suite.
    The Acrobat 9.x product family passed into End of Support mid-year of 2013.
    The product isn't compatible with contemporary OSs or Office suite.
    You may have to step up into the Acrobat XI product family.
    Be well...

  • Can I Create Chapters Separately in iBooks Author and Merge Into a Single iBook?

    In a print page layout package like InDesign, chapters of a book can be created separately and then merged into one book file. Is it possible to do that to create an iBook in iBooks Author?
    Thank you.

    Yes, it is possible and very easy to do.
    If you want your chapters/sections/pages to have the same layout and colour scheme... make your template and and save as template - or use teh same free template for each chapter.
    Create a Master version - and  it is to this you will eventually copy  and paste youe separate chapters.
    Just select and copy the chapter and open the master.. then paste in the left "Book" column.
    If you are using  different  chapter layouts - It also takes its template and that also appears in the  hidden Layout tree.
    I use this method on every book, simply because it does not slow down the machine. A  multi chapter book with videos and  photo images makes a big  file - which is slow to process every time you preview or check things.

  • Compiling a CSS into SWF without merged SDK and dynamically loading

    I have a flex application that is built with the SDK merged in (for my own good reasons). This application dynamically loads a style SWF that was built without the SDK merged. Unfortunately, it seems that the loaded SWF fails to resolve its references with the SDK and gives me a 1014 run-time error.
    If I merge the SDK into the CSS SWF then it works. If I set both my application and the CSS SWF to use the SDK as an RSL then it works. In short the matrix is:
    CSS SWF, SDK merged?
    Application, SDK merged?
    Works?
    Yes
    Yes
    Yes
    Yes
    No
    Yes
    No
    Yes
    No
    No
    No
    Yes
    I do not want a big CSS SWF to dynamically load with all the SDK in it when I already have the SDK loaded with my application. Any help much appreciated.

    Hi,
    In you rsl project properties, go to Flex Library Build Path and go to library path tab. Here you can edit your imported library. There's no need in RSL to import the libraries merge into code but external(even the Adobe libraries should be loaded as external) cause you load it already from your application project (as rsl or merge into code).
    Bye!

  • How do I take a 4-piece chart design and merge into one chart?

    How do I take a 4-piece design chart and merge into one chart?

    But it can be done with Adobe Acrobat, or the PDF Pack online service.

  • [svn:osmf:] 14306: PARB changes: Merge seekBegin and seekEnd event types into a single seekingChange event type .

    Revision: 14306
    Revision: 14306
    Author:   [email protected]
    Date:     2010-02-21 10:48:21 -0800 (Sun, 21 Feb 2010)
    Log Message:
    PARB changes: Merge seekBegin and seekEnd event types into a single seekingChange event type.  Add seeking as a getter to the SeekEvent class.  Update test code and samples accordingly.
    Modified Paths:
        osmf/trunk/apps/samples/framework/CuePointSample/src/CuePointSample.mxml
        osmf/trunk/apps/samples/framework/DynamicStreamingSample/src/DynamicStreamingSample.mxml
        osmf/trunk/apps/samples/plugins/AkamaiPluginSample/src/AkamaiPluginSample.mxml
        osmf/trunk/apps/samples/plugins/CaptioningSample/src/CaptioningSample.mxml
        osmf/trunk/framework/OSMF/.flexLibProperties
        osmf/trunk/framework/OSMF/org/osmf/elements/DurationElement.as
        osmf/trunk/framework/OSMF/org/osmf/elements/ListenerProxyElement.as
        osmf/trunk/framework/OSMF/org/osmf/elements/compositeClasses/CompositeSeekTrait.as
        osmf/trunk/framework/OSMF/org/osmf/elements/compositeClasses/ParallelSeekTrait.as
        osmf/trunk/framework/OSMF/org/osmf/events/MediaErrorEvent.as
        osmf/trunk/framework/OSMF/org/osmf/events/SeekEvent.as
        osmf/trunk/framework/OSMF/org/osmf/media/MediaPlayer.as
        osmf/trunk/framework/OSMF/org/osmf/metadata/TemporalFacet.as
        osmf/trunk/framework/OSMF/org/osmf/traits/SeekTrait.as
        osmf/trunk/framework/OSMF/org/osmf/utils/TraitEventDispatcher.as
        osmf/trunk/framework/OSMFTest/org/osmf/elements/TestDurationElement.as
        osmf/trunk/framework/OSMFTest/org/osmf/elements/TestParallelElementWithSeekTrait.as
        osmf/trunk/framework/OSMFTest/org/osmf/elements/audioClasses/TestAudioSeekTrait.as
        osmf/trunk/framework/OSMFTest/org/osmf/media/TestMediaPlayer.as
        osmf/trunk/framework/OSMFTest/org/osmf/traits/TestSeekTrait.as
        osmf/trunk/framework/OSMFTest/org/osmf/utils/DynamicSeekTrait.as
        osmf/trunk/framework/OSMFTest/org/osmf/utils/TestTraitEventDispatcher.as
        osmf/trunk/libs/ChromeLibrary/src/org/osmf/chrome/controlbar/widgets/RecordButton.as
        osmf/trunk/plugins/CaptioningPluginTest/src/CaptioningPluginTest.mxml
        osmf/trunk/plugins/MASTPlugin/org/osmf/mast/adapter/MASTAdapter.as
        osmf/trunk/plugins/MASTPlugin/org/osmf/mast/managers/MASTConditionManager.as

    ls -l /var/run/lighttpd/
    And how are you spawning the php instances? I don't see that in the daemons array anywhere.
    EDIT: It looks like the info in that page is no longer using pre-spawned instances, but lighttpd adaptive-spawn. The documentation has been made inconsistent it looks like.
    You will note that with pre-spawned information, the config looks different[1].
    You need to do one or the other, not both (eg. choose adaptive-spawn, or pre-spawn..not both).
    [1]: http://wiki.archlinux.org/index.php?tit … oldid=8051 "change"

  • Buggy iTunes can't merge CD1 and CD2 into one

    Macbook pro 13" 4GB ram 500GB HD. OS X Yosemite with latest iTunes.
    I am ripping two CDs of same album into ALAC format. I encounter problem when I group them into one album.
    1. Change album name from "XXXXX [Disc1]" and "XXXXX [Disc2] into same name "XXXXX", the "XXXXX [Disc 2]" in picture 1 doesn't change at all after ok pressed;
    2. When I delete in an album the 3rd item content (composer?), picture 2 error appears. 
    Please help.
    Picture1 Picture2

    Having restart the iTunes, all songs but the last one in CD2 are merged into CD1.  So what should I do to the last song?

  • My partner and i have seperate i tunes accounts,can these be merged into 1 account for ease of use ?

    My Partner and i have seperate i tunes accounts,can these be merged into 1 account for ease of use ?

    This is not possible.
    From Here   http://support.apple.com/kb/HE37
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.

  • CONNECT BY with CROSS JOIN and WHERE not executing as described in doc

    Hello all,
    please see these two statements. They are the same, but the 1st uses t1 INNER JOIN t2 while the snd uses a CROSS JOIN with WHERE.
    The 2nd statement shows one row more than the first, but the CROSS JOIN with WHERE is the same as the INNER JOIN.
    The result would be OK if Oracle did:
    JOIN -> CONNECT BY PRIOR -> WHERE
    But according to the docs it does:
    JOIN (and WHEREs for JOINS) -> CONNECT BY PRIOR -> Rest of WHERE
    See http://docs.oracle.com/cd/E11882_01/server.112/e26088/queries003.htm#SQLRF52332 for details. There it says:
    Oracle processes hierarchical queries as follows:
    A join, if present, is evaluated first, whether the join is specified in the FROM clause or with WHERE clause predicates.
    The CONNECT BY condition is evaluated.
    Any remaining WHERE clause predicates are evaluated.
    +.....+
    Is this a bug? I'd say yes, because it differs from the docs and it also is not what people are used to ("a,b WHERE" is the same as "a INNER JOIN b").
    Thanks,
    Blama
    --Statement 1:
    WITH t1
    AS
    (SELECT 1 a, 2 b FROM DUAL UNION ALL
    SELECT 2 a, 3 b FROM DUAL UNION ALL
    SELECT 3 a, 4 b FROM DUAL UNION ALL
    SELECT 4 a, 5 b FROM DUAL UNION ALL
    SELECT 5 a, 6 b FROM DUAL),
    t2 AS
    (SELECT 1 c FROM DUAL UNION ALL
    SELECT 2 c FROM DUAL UNION ALL
    SELECT 3 c FROM DUAL UNION ALL
    SELECT 5 c FROM DUAL)
    SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
    FROM t1 INNER JOIN t2
    ON t1.a = t2.c
    CONNECT BY t1.a = PRIOR t1.b
    START WITH t1.a = 1
    ORDER BY
    1,2,3;
    --Result:
    --1     1     2     1     /1
    --2     2     3     2     /1/2
    --3     3     4     3     /1/2/3
    --Statement 2:
    WITH t1
    AS
    (SELECT 1 a, 2 b FROM DUAL UNION ALL
    SELECT 2 a, 3 b FROM DUAL UNION ALL
    SELECT 3 a, 4 b FROM DUAL UNION ALL
    SELECT 4 a, 5 b FROM DUAL UNION ALL
    SELECT 5 a, 6 b FROM DUAL),
    t2 AS
    (SELECT 1 c FROM DUAL UNION ALL
    SELECT 2 c FROM DUAL UNION ALL
    SELECT 3 c FROM DUAL UNION ALL
    SELECT 5 c FROM DUAL)
    SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
    FROM t1 CROSS JOIN t2
    WHERE t1.a = t2.c
    CONNECT BY t1.a = PRIOR t1.b
    START WITH t1.a = 1
    ORDER BY
    1,2,3;
    --Result:
    --1     1     2     1     /1
    --2     2     3     2     /1/2
    --3     3     4     3     /1/2/3
    --5     5     6     5     /1/2/3/4/5My details:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for Solaris: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    blama wrote:
    Hello Paul,
    that means that "a,b" isn't the same as "a CROSS JOIN b".
    I don't think that that is really the case.
    Do you have docs on this one?No explicit docs just (my) logic - having said that, I suppose it is implied that if you are doing ANSI style joins, it's not the where clauses that
    are specifying the join.
    If you do t1,t2 where t1.a=t2.a then Oracle figures out the kind of join from the (relevant) where clauses and treats the other where clauses after the CONNECT BY.
    If you do t1 cross join t2 where t1.a=t2.a then you are saying the join is completely specified by the CROSS JOIN - i.e it's Cartesian. Oracle doesn't look at the where clauses for this. Therefore
    all where clauses are treated as 'other' and are evaluated after the CONNECT BY.
    So, in my mind it's 10g that has the bug.

  • Performance considerations between a cross join and inner join

    Hi there,
    What's the performance difference and impact on running a cross-join based query against an inner join based query?
    Regards and thanks

    Before going to the performance issue - ensure you get the required data and not just some data shown.
    Performance should be checked only between equivalent queries which produce same output but with different processing.
    Are you sure you get same output in cross join as well as inner join?
    If so pass on your different queries and then discuss with one is better.

Maybe you are looking for