Skip to content

Commit 559c5fa

Browse files
CopilotPhenX
andcommitted
Fix Oracle MERGE syntax: reorder WHEN clauses and fix spacing
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
1 parent 80f2ec8 commit 559c5fa

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/PhenX.EntityFrameworkCore.BulkInsert.Oracle/OracleDialectBuilder.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,20 @@ public override string BuildMoveDataSql<T>(
6060
q.AppendJoin(" AND ", matchColumns, (b, col) => b.Append($"{PseudoTableInserted}.{col} = {PseudoTableExcluded}.{col}"));
6161
q.AppendLine(")");
6262

63+
// WHEN NOT MATCHED clause should come before WHEN MATCHED in Oracle
64+
q.Append("WHEN NOT MATCHED THEN INSERT (");
65+
q.AppendColumns(insertedColumns);
66+
q.AppendLine(")");
67+
68+
q.Append("VALUES (");
69+
q.AppendJoin(", ", insertedColumns, (b, col) => b.Append($"{PseudoTableExcluded}.{col.QuotedColumName}"));
70+
q.Append(")");
71+
6372
if (onConflictTyped.Update != null)
6473
{
6574
var columns = target.GetColumns(false);
6675

67-
q.Append("WHEN MATCHED");
76+
q.Append(" WHEN MATCHED");
6877

6978
if (onConflictTyped.RawWhere != null || onConflictTyped.Where != null)
7079
{
@@ -77,18 +86,11 @@ public override string BuildMoveDataSql<T>(
7786
AppendConflictCondition(q, target, context, onConflictTyped);
7887
}
7988

80-
q.AppendLine(" THEN UPDATE SET ");
89+
q.Append(" THEN UPDATE SET ");
8190
q.AppendJoin(", ", GetUpdates(context, target, columns, onConflictTyped.Update));
82-
q.AppendLine();
8391
}
8492

85-
q.Append("WHEN NOT MATCHED THEN INSERT (");
86-
q.AppendColumns(insertedColumns);
87-
q.AppendLine(")");
88-
89-
q.Append("VALUES (");
90-
q.AppendJoin(", ", insertedColumns, (b, col) => b.Append($"{PseudoTableExcluded}.{col.QuotedColumName}"));
91-
q.AppendLine(")");
93+
q.AppendLine();
9294
}
9395

9496
// No conflict handling

0 commit comments

Comments
 (0)