Here’s the structure of a query I came across:
MERGE INTO TABLE t
USING (SELECT ? id, ? email, ? cr_date, ? info, ? status FROM dual) n
ON t.id=n.id and t.email=n.email
WHEN MATCHED THEN UPDATE SET z.info = n.info z.status='Y'
WHEN NOT MATCHED THEN INSERT (info, status) VALUES (n.info, n.status)
I’ve read up on using DUAL to return SYSDATE or other operations… is the SELECT simply returning some input values into a table (row) to simplify further operations in the other clauses?
Thanks!
The code you came across is meant to update a single row, or create it if it doesn’t exist.
DUAL is a special system table containing just one row.
Selecting from DUAL is a workaround for Oracles inability to do simply:
Note that it doesn’t have to be
dual, it can be any one-row-table or even a query that returns one row.is equivalent to:
and
Since version 10g, the
dualtable has a special access path which shows up in the execution plan as “fast dual”, which results in 0 consistent gets, which isn’t possible to achive on your own using other tables.