We are migrating from Oracle to H2 database and came across the following compatibility issue.
The built in function REGEXP_REPLACE behaves differently in Oracle and H2 when we try to replace a string with an empty string.
Example:
select REGEXP_REPLACE('Hello World', ' +', '') from dual;
-> Oracle returns HelloWorld but H2 returns null.
As per H2 documentation the REGEXP_REPLACE returns null if one of the parameters is null.
Is this behaviour intentional or is this a bug? I think it is a valid use case to replace a match with an empty string.
Are there any workarounds available?
We are using H2 version 1.4.190 and Mode=Oracle
I’ve also tested the behaviours for the following statements:
select REGEXP_REPLACE('Hello World', ' +', NULL) from dual;
-> Oracle returns HelloWorld
-> H2 returns null
select REGEXP_REPLACE('Hello World', '', 'a') from dual;
-> Oracle returns 'Hello World'
-> H2 returns null
select REGEXP_REPLACE('Hello World', NULL , 'a') from dual;
-> Oracle returns 'Hello World'
-> H2 returns null
select REGEXP_REPLACE('', ' +', 'a') from dual;
-> Oracle returns NULL
-> H2 returns NULL
Thanks,
Ronnie