目标表中的重复项更新/合并(Oracle 11g)

时间:2018-01-26 17:17:27

标签: oracle11g merge duplicates

我一直在努力争取这个,我会很感激一些建议。有关使用以下内容的更新/合并查询中涉及的源表和目标表的位上下文:

model

通过连接两个表的select语句创建SRC; select语句如下所示:

'Declare the main SQLite data access objects
Dim objConn As SQLiteConnection
Dim objCommand As SQLiteCommand
Dim objReader As SQLiteDataReader
'SQLiteDateFormats.UnixEpoch

Dim CONNECTION_STR As String = "Data Source=" & FileName & "; Version = 3; Read Only = True;" 'DateTimeFormat=UnixEpoch;"

TableName = "[" & TableName & "]"

Try
    'Create a new database connection
    objConn = New SQLiteConnection(CONNECTION_STR)

    'Open the connection
    objConn.Open()

    'Prepare Commands to Run
    objCommand = objConn.CreateCommand()

    'Determine Size of Table
    CommandToRun = "SELECT COUNT(*) FROM " & TableName & ";"
    objCommand.CommandText = CommandToRun
    Dim RowCount As Long = objCommand.ExecuteScalar
    lblRowCount.Text = RowCount

    'Create a new SQL command to read all records from the selected table
    CommandToRun = "Select * From " & TableName & ";"
    objCommand.CommandText = CommandToRun

    Dim ds As New DataSet

    Using da As New SQLiteDataAdapter(objCommand)
        da.MissingSchemaAction = MissingSchemaAction.AddWithKey
        da.Fill(ds, TableName)

    End Using
    dgSQLite.DataSource = ds.Tables(TableName)
    dgSQLite.AutoResizeRows()
    dgSQLite.AutoResizeColumns()

    Me.Refresh()
Catch ex As Exception
        MyErrorBox(ex)
    End If
Finally
    'Cleanup and close the connection
    If Not IsNothing(objConn) Then
        objConn.Close()
        objConn.Dispose()
    End If
End Try

我正在尝试使用SRC更新目标表(DES),在Format_Code上加入/匹配如下:

SRC Table

Format_Code     ACR
----------------------------
BAD             5  
SAD             7
MAD             2

我收到以下错误(因为我认为目标表中有重复项)但不确定如何忽略/绕过它们。 SRC不包含重复项,但DES确实具有重复的Format_Code。在更新期间,我想要更新重复行的一个实例或完全忽略重复(少量重复,以便我可以在必要时手动更新)

Select distinct a.Format_Code, b.ACR from Formats a
Inner join Codes b on lower(a.Format_Name) = lower(b.Format_Name)

这是我第一次发帖,如果我犯了任何新手错误,请道歉

1 个答案:

答案 0 :(得分:0)

  

...因为dml活动很大......

尝试COMMIT,然后运行MERGE。有什么改进吗?