Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does H2 support PLSQL when using Oracle mode?

I'm trying to write some functional tests for our java application using H2 in-memory database. Since we use Oracle as our production DB, some of the code is written in PL/SQL. So I switched on Oracle compatibility mode and now my url looks like this: jdbc:h2:mem:test;MODE=Oracle.

The actual application code that I'm having troubles with looks like this (note, both sequence and table have been created before the call):

CallableStatement = con.prepareCall(
    " begin insert into profiles(" + PROFILE_FIELDS + ") " +
    " values (sq_profiles.nextval, ?, ?, ?, ?, ?) " + 
    " returning profile_id into ?; end;");

It fails with the same error that this sample code I wrote to test begin ... end; behavior:

Connection con = connectionProvider.getConnection()
con.prepareStatement("CREATE TABLE test (id INT NOT NULL)").execute()
con.prepareStatement("INSERT INTO test SELECT 1 FROM dual").execute()
con.prepareStatement("BEGIN INSERT INTO test SELECT 2 FROM dual; END;").execute()

The error I get:

Syntax error in SQL statement "BEGIN INSERT[*] INTO TEST SELECT 2 FROM DUAL; END; "; SQL statement:
BEGIN INSERT INTO test SELECT 2 FROM dual; END; [42000-167]

So my question is: are begin ... end; blocks supported by H2? If yes, what could be wrong with the code above?

Thanks.

like image 486
Andrew Logvinov Avatar asked Jan 15 '23 19:01

Andrew Logvinov


1 Answers

No, H2 Oracle compatibility mode does not mean support for such a PL/SQL. As told in H2 documentation, Oracle compatibility mode brings following:

  • For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
  • When using unique indexes, multiple rows with NULL in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
  • Concatenating NULL with another value results in the other value.
like image 114
Mikko Maunu Avatar answered Jan 26 '23 01:01

Mikko Maunu