Oracle OJDBC MERGE Statement and Generated Keys

82 Views Asked by At

Does Oracle ~>12 support generated keys using a Merge statement? Some sudo code..

MERGE INTO TARGET_TABLE TRG
USING (SELECT CAST(? AS NUMBER) AS ID FROM DUAL) SRC
ON (TRG.ID = SRC.ID)
WHEN MATCHED THEN UPDATE SET....
WHEN NOT MATCHED THEN
    INSERT(ID....)
    VALUES(MYSEQ.NEXTVAL...)

The prepared statement is set up;

try (PreparedStatement pstmt =
              connection.prepareStatement(
                  loadStatement(sqlName, connection, getClass()), new String[] {ID})) {
...
int inserted = pstmt.executeUpdate();
ResultSet rs = pstmt.getGeneratedKeys();

List<Long> keys = new ArrayList<>(inserted);
while (rs.next) {
    rs.getLong(1);
}
return keys;
...

I have in-memory tests where the connection uses the H2 driver running the very same SQL and PreparedStatment and that returns the generated key just fine, but Oracle does not.

Reviewing the docs it would suggest it does not?

Thanks!

0

There are 0 best solutions below