|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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);
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > sql problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|