Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.oracle    |    Overblown overpriced overengineered SHIT    |    2,288 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 1,239 of 2,288    |
|    Spare Brain to All    |
|    Can MERGE replace UPDATE/INSERT duo on a    |
|    06 Apr 04 16:18:30    |
   
   XPost: comp.databases.oracle.misc   
   From: spare_brain@yahoo.com   
      
   Hi Folks,   
      
   I need to INSERT data into the table where the row may already be present.   
   Can MERGE help me out? I'm limited to using SQL only, and thew DB is Oracle   
   9.2.   
      
   The low-tech solution would be to issue a SELECT and do an update if the row   
   is present, and an INSERT if the row is absent. I thought MERGE can help you   
   out - but I'm not able to do it. here's the merge statement I tried, which   
   seems to affect zero rows!   
      
   merge into employee s   
   using   
   (select * from employee where user_id = 'john123') st   
   ON (s.user_id = st.user_id)   
   when matched then   
    update set s.pay=50000   
   when not matched then   
    insert (s.user_id, s.pay, s.service_name, s.authorized_for) values   
    ('john123', 50000, 'foo', 'ALL')   
   /   
      
   Thanks   
   SB   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca