仅当存在两列(两者的组合)的值时才更新列,否则在Oracle DB中插入所有值

时间:2017-11-15 11:03:34

标签: sql oracle insert-update

在我的Oracle数据库中,表'basic_comment'中有3列&列是(product_idcommentcomment_id)。

只有当列(product_id和comment_id)的组合已经存在时,我才必须更新列'注释',否则插入所有三列。例如:

product_id     comment     comment_id  
Ac2108         fixed          5  
Ac7108         configure      3  
As2108         fixed          5  

所以这里如果(Ac2108和5)存在,那么对于同一行,我需要将注释从'fixed'更改为'configure',否则则插入所有列。列将从另一个表"static_comment"插入 我已尝试合并查询,但它也在“basic_comment”表中更新其他行。

MERGE 
INTO  basic_comment a 
USING static_comment b
ON  ( a.product_id = b.product_id and a.comment_id = b.comment_id )    
WHEN MATCHED 
THEN 
 UPDATE
SET a.comment = b.comment
WHEN NOT MATCHED
THEN 
INSERT ( a.product_id
, a.comment
, a.comment_id
VALUES ( b.product_id
, b.comment
, b.comment_id);

1 个答案:

答案 0 :(得分:0)

如果合并有问题,可以做两个单独的陈述,显然不是那么快,但如果数据集很小就会做

Sub mmtlink()

Dim IE As New SHDocVw.InternetExplorer
Dim htmldoc As MSHTML.HTMLDocument
Dim all As MSHTML.IHTMLElementCollection
Dim one As MSHTML.IHTMLElement

'Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True

IE.navigate "https://www.makemytrip.com/air/search?tripType=O&itinerary=DEL-DXB-D-30Nov2017&paxType=A-1&cabinClass=E"

 Do While IE.Busy = True Or IE.readyState <> 4
 Loop

    Set htmldoc = IE.document

    Set all = htmldoc.getElementsByClassName("sortbytype")
    For Each one In all
       If one.getAttribute("Innertext") = "from BOM (early)" Then
            one.Click
       End If
    Next one

Next i
End Sub