SunQuest
           Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old December 16th, 2004, 11:35 PM
HussainA_ONE HussainA_ONE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 HussainA_ONE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sql problem

hi everyone
i have made 2 table in oracle and have connected it with developer6i . Now both the table have same fields . Fields are as such
article_no varchar2(5),
si0 number(2),
si1 number(2),
si2 number(2),
si3 number(2);

and tables name are stock and purchase
if data enter in purchase.article_no matches with stock.article_no then it should add data of purchase.si0, purchase.si1, purchase.si2, and purchase.si3 into data already in stock.si0, stock.si1, stock.si2, and stock.si3 respectively. else it should insert a new record in stock table containing same data as in purchase record.
plz guys this is urgent plz help me out in this.

Reply With Quote
  #2  
Old January 27th, 2005, 08:23 PM
wubandit99 wubandit99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 30 wubandit99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 4
I believe this is what you want...


Code:
MERGE INTO stock s
USING (
   SELECT
        article_no, si0, si1, si2, si3
   FROM
        purchase
 ) p
ON (s.article_no = p.article_no)
WHEN MATCHED THEN
   UPDATE
   SET
     s.si0 = s.si0 + p.si0,
     s.si1 = s.si1 + p.si1,
     s.si2 = s.si2 + p.si2,
     s.si3 = s.si3 + p.si3
WHEN NOT MATCHED THEN
   INSERT (s.article_no, s.si0, s.si1, s.si2, s.si3)
   VALUES (p.article_no, p.si0, p.si1, p.si2, p.si3);

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > sql problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway