I'm trying to insert some entries into my table and do nothing when the entry already exists. My primary key consists of more than one column (event_timestamp, device_id, path, message_id).
When I try something like following statement in JDBC:
MERGE INTO events dest
USING ( SELECT event_timestamp, device_id, path, message_id from events) src
ON (dest.event_timestamp = src.event_timestamp
and dest.device_id = src.device_id
and dest.path = src.path
and dest.message_id = src.message_id)
WHEN NOT MATCHED THEN
INSERT (event_timestamp, device_id, path, message_id, text, direction, speed, net, gross)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
Nothing gets inserted.
With a normal statement like :
INSERT (event_timestamp, device_id, path, message_id, text, direction, speed, net, gross) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
everything is inserted without problems.
I also tried changing the select statement to select from DUAL
instead of events like :
MERGE INTO events dest
"USING ( SELECT event_timestamp, device_id, path, message_id from DUAL) src
ON (dest.event_timestamp = src.event_timestamp
and dest.device_id = src.device_id
and dest.path = src.path
and dest.message_id = src.message_id)
WHEN NOT MATCHED THEN
INSERT (event_timestamp, device_id, path, message_id, text, direction, speed, net, gross)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
But then I get the exception: ORA-00904: invalid identifier
What can I do to make it work?