H2 database and functions in separate schemas

99封情书 提交于 2019-12-06 03:45:11

H2 doesn't support packages. What you could do is create the function using a different name, for example: PERMISSION_TOOLS_GET_ACCESS_LEVEL. The disadvantage is that you need to change the query as well. Or, you create a schema PERMISSION_TOOLS and the method there:

create schema PERMISSION_TOOLS;
CREATE ALIAS PERMISSION_TOOLS.GET_ACCESS_LEVEL as $$
String nextPrime(String value) {
    return new BigInteger(value).nextProbablePrime().toString();
}
$$;
select permission_tools.get_access_level(1) from dual;

Please not this will not yet work in H2 version 1.2.131 (which is the version you are using according to the error message code you got). The reason is that 'functions in schemas' was just recently implemented (in version 1.2.135). Actually I suggest to upgrade to version 1.2.138, because there was a bug fixed related to this feature in earlier versions. The disadvantage of creating the method is a special schema is: if you do create such functions in schemas other than PUBLIC, then the database can not be opened with older versions of H2.

To answer @thomas-mueller, if you don't care what the procedure does. H2 uses this pattern to call the stored procedure

database.schema.procedure_name

So if your are testing give the test database a name say test and the way you will call the stored procedure in code will be like call test.PERMISSION_TOOLS.GET_ACCESS_LEVEL

See my answer in How to define oracle package procedure in h2 for testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!