What causes ORA-30926 unable to get a stable set of rows?
The USING subquery returns more than one row for a key. Add ROW_NUMBER() OVER (PARTITION BY key ORDER BY updated_at DESC) and keep rn = 1.
Gerador de upsert
Nomeie tabela, chave e colunas e receba a instrução que o Oracle Database realmente aceita, com uma guarda para que uma linha antiga nunca sobrescreva uma nova. Abaixo: como a mecânica funciona, o que quebra e como a Datrise carrega o Oracle Database de forma incremental.
As notas técnicas desta página estão em inglês.
Instrução · MERGE INTO … USING
MERGE INTO deals t
USING (SELECT id, name, stage, amount, owner_id, updated_at FROM deals_staging) s
ON (t.id = s.id)
WHEN MATCHED THEN UPDATE SET
t.name = s.name,
t.stage = s.stage,
t.amount = s.amount,
t.owner_id = s.owner_id,
t.updated_at = s.updated_at
WHERE s.updated_at > t.updated_at
WHEN NOT MATCHED THEN
INSERT (id, name, stage, amount, owner_id, updated_at)
VALUES (s.id, s.name, s.stage, s.amount, s.owner_id, s.updated_at);Oracle introduced MERGE in 9i and it remains the upsert. The source is any subquery, the ON clause is in parentheses, and each branch can carry its own WHERE: the generated statement puts the watermark test on the UPDATE branch so stale rows are ignored rather than written. Columns used in ON cannot appear in the UPDATE SET list.
For batch loads, direct-path insert (the APPEND hint on the INSERT branch) and parallel DML make MERGE scale with the table rather than with row count. Oracle treats an empty string as NULL, so a CRM field that was cleared and one that was never set look the same after the load; if that distinction matters, land a separate flag column.
The USING subquery returns more than one row for a key. Add ROW_NUMBER() OVER (PARTITION BY key ORDER BY updated_at DESC) and keep rn = 1.
No. ORA-38104 rejects updating any column referenced in the ON clause. Keys are stable by design; if a source renumbers ids, that is a delete plus insert.
In the MATCHED branch: WHEN MATCHED THEN UPDATE SET … DELETE WHERE s.is_deleted = 1 removes rows the source marked deleted, in the same statement.
A Datrise entrega entidades de CRM e SaaS no Oracle Database com exatamente esta mecânica, uma marca d'água sobre updated-at e colunas tipadas, então a instrução acima é a que roda por você. Entre na lista de espera para acesso antecipado.
Explorar o catálogo de integrações