If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Merge

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-11, 08:40
citi citi is offline
Registered User
 
Join Date: Aug 2007
Posts: 45
Merge

Is MERGE supported on V8 (Z/os)?

I'm attempting to execute the following:

MERGE
INTO SERDB.I117_ANE_FINAL_T FINALL
USING (
SELECT I110_EXPLOITATION, I110_NEGLECT, I110_PHYSICAL, I110_PSYCHOLOGICAL, I110_SEXUAL
FROM SERDB.I110_ANE_INITIAL_T INITIAL
WHERE I110_FORM_STATUS = 'A')
ON INITIAL.I110_ABU_NEG_EXP_ID = FINALL.I117_ABU_NEG_EXP_ID
AND FINALL.I117_FINAL_TYPE = 'MR'
WHEN MATCHED THEN
UPDATE
SET FINALL.I117_EXPLOITATION = INITIAL.I110_EXPLOITATION,
FINALL.I117_NEGLECT = INITIAL.I110_NEGLECT,
FINALL.I117_PHYSICAL = INITIAL.I110_PHYSICAL,
FINALL.I117_PYSCHOLOGICAL = INITIAL.I110_PSYCHOLOGICAL,
FINALL.I117_SEXUAL = INITIAL.I110_SEXUAL


I'm receiving a SQLState: 42601 error.
Reply With Quote
  #2 (permalink)  
Old 02-04-11, 09:28
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
No. You need V9 z/OS to use Merge.
Reply With Quote
  #3 (permalink)  
Old 02-04-11, 09:38
citi citi is offline
Registered User
 
Join Date: Aug 2007
Posts: 45
Ok.

Would it be possible to perform an insert on a destination table using values selected from a primary table? The columns are of the same datatype.
Reply With Quote
  #4 (permalink)  
Old 02-04-11, 09:59
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
Yes, you can do an Insert (or an Update) from one table to another. Not sure why you are asking about an Insert as your example is an Update. Since I don't see an Insert, the following Insert is a guess. I think the Update will do the same as your Merge.
Code:
INSERT INTO SERDB.I117_ANE_FINAL_T
  SELECT I110_EXPLOITATION
       , I110_NEGLECT
       , I110_PHYSICAL
       , I110_PSYCHOLOGICAL
       , I110_SEXUAL
  FROM SERDB.I110_ANE_INITIAL_T INITIAL
  WHERE I110_FORM_STATUS = 'A'


UPDATE SERDB.I117_ANE_FINAL_T FINALL
SET ( FINALL.I117_EXPLOITATION 
    , FINALL.I117_NEGLECT      
    , FINALL.I117_PHYSICAL     
    , FINALL.I117_PYSCHOLOGICAL
    , FINALL.I117_SEXUAL
    )
  =
    (SELECT INITIAL.I110_EXPLOITATION
          , INITIAL.I110_NEGLECT
          , INITIAL.I110_PHYSICAL
          , INITIAL.I110_PSYCHOLOGICAL
          , INITIAL.I110_SEXUAL 
     FROM SERDB.I110_ANE_INITIAL_T INITIAL
     WHERE INITIAL.I110_ABU_NEG_EXP_ID = FINALL.I117_ABU_NEG_EXP_ID
       AND INITIAL.I110_FORM_STATUS    = 'A'
    )
WHERE FINALL.I117_FINAL_TYPE = 'MR'
Reply With Quote
  #5 (permalink)  
Old 02-04-11, 10:18
citi citi is offline
Registered User
 
Join Date: Aug 2007
Posts: 45
Thank you!
Reply With Quote
  #6 (permalink)  
Old 02-07-11, 02:11
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by Stealth_DBA View Post
No. You need V9 z/OS to use Merge.
No. On my last mainframe assignment the client upgraded to V8 and from that time I could use the new SQL capabilities like CTE's and MERGE. Sometimes the V8 runs in V7-modus (I recall 3 stages) and then you cannot use the new SQL thingies.
Reply With Quote
  #7 (permalink)  
Old 02-07-11, 05:57
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
No. Merge is not available in DB2 V8 z/OS. CTE became available but not Merge. It first became available in V9.1. Here is the entry in Info Center.

DB2 9 - What's new - MERGE and SELECT FROM MERGE statements

We currently have DB2 V8 z/OS (in the middle of V9.1 Upgrade) and MERGE does not work.
Reply With Quote
  #8 (permalink)  
Old 02-07-11, 06:37
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by Stealth_DBA View Post
We currently have DB2 V8 z/OS (in the middle of V9.1 Upgrade) and MERGE does not work.
Yep, just checked my old docs. A lot of new features but no merge. It seems that my memory serves my wrong.... (is the english?)
I'll never contradict you again
Reply With Quote
  #9 (permalink)  
Old 02-07-11, 13:46
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
In DB2 for z/OS,
you can specify only "USING (VALUES ... )".

See Information Center.
DB2 10 for z/OS > DB2 reference information > DB2 SQL > Statements MERGE

I think that you can't use MERGE to update a table from another table on z/OS.
Reply With Quote
  #10 (permalink)  
Old 02-07-11, 14:11
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
I thought that AND EXISTS should be added.
Because, if there was no matching row in SERDB.I110_ANE_INITIAL_T INITIAL,
subselect in SET clause would return null values.

Code:
UPDATE SERDB.I117_ANE_FINAL_T FINALL
   SET ( FINALL.I117_EXPLOITATION 
       , FINALL.I117_NEGLECT      
       , FINALL.I117_PHYSICAL     
       , FINALL.I117_PYSCHOLOGICAL
       , FINALL.I117_SEXUAL
       )
     =
       (SELECT INITIAL.I110_EXPLOITATION
             , INITIAL.I110_NEGLECT
             , INITIAL.I110_PHYSICAL
             , INITIAL.I110_PSYCHOLOGICAL
             , INITIAL.I110_SEXUAL 
         FROM  SERDB.I110_ANE_INITIAL_T INITIAL
         WHERE INITIAL.I110_ABU_NEG_EXP_ID = FINALL.I117_ABU_NEG_EXP_ID
           AND INITIAL.I110_FORM_STATUS    = 'A'
       )
 WHERE FINALL.I117_FINAL_TYPE = 'MR'
   AND EXISTS
       (SELECT *
         FROM  SERDB.I110_ANE_INITIAL_T INITIAL
         WHERE INITIAL.I110_ABU_NEG_EXP_ID = FINALL.I117_ABU_NEG_EXP_ID
           AND INITIAL.I110_FORM_STATUS    = 'A'
       )
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On