Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> MERGE INTO without WHEN MATCHED, possible?
I try to insert a list of rows, where some rows are
already present in the table and should not be
reinserted, into a table with the MERGE INTO
statement using the C-API.
The primary key (ID) for that table is generated
using a sequence and a trigger.
Oracle complains
ORA-00905: missing keyword
when the WHEN MATCHED THEN part is missing.
Is it allowed to leave the WHEN MATCHED part out? Or if not, is it possible fill it with some harmless and fast noop?
1 MERGE INTO
2 USING ( SELECT field1, field2 FROM tableA
3 WHERE a.field1 = 'y' and a.field2 = 'YYY' ) a
4 ON ( a.field1 = 'y' and a.field2 = 'YYY' )
5 WHEN NOT MATCHED THEN INSERT (field1,field2 )
6* VALUES( 'y', 'YYY' )
SQL-PLUS>/
VALUES( 'y', 'YYY' )
*
CREATE UNIQUE INDEX idx_fk_tableA ON tableA(field1,field2) /
INSERT INTO tableA(field1, field2)
values( 'X' , 'XXX' )
/
--