简体   繁体   English

如何使用 jOOQ 将 Oracle PL/SQL 常量作为参数传递?

[英]How do I pass Oracle PL/SQL constants as parameters using jOOQ?

I'm trying to convert some Oracle queries using PL/SQL to jOOQ.我正在尝试将一些使用 PL/SQL 的 Oracle 查询转换为 jOOQ。 Most package queries, stored procedures, etc. are easy, using the code generator.大多数包查询、存储过程等都很容易,使用代码生成器。 However there's one feature used in several places for which I haven't found a jOOQ alternative:但是,有几个地方使用了一个功能,但我还没有找到 jOOQ 替代方案:

begin
  MY_SCHEMA.MY_PACKAGE.MY_QUERY(some_param => MY_SCHEMA.MY_PACKAGE.SOME_CONSTANT)
  -- more code
end;

I can call the query just fine, but I'm not sure how to pass the MY_SCHEMA.MY_PACKAGE.SOME_CONSTANT value into it.我可以很好地调用查询,但我不确定如何将MY_SCHEMA.MY_PACKAGE.SOME_CONSTANT值传递给它。 The jOOQ code generator doesn't seem to generate anything for the constant (at least, I can't find anything similarly named). jOOQ 代码生成器似乎没有为常量生成任何内容(至少,我找不到任何类似的名称)。 Do I need to enable a feature on the generator?我需要在生成器上启用一个功能吗? Or do I need to query those constants?还是我需要查询这些常量? If so, how?如果是这样,如何?

Enabling PL/Scope for this to work启用 PL/Scope 使其工作

jOOQ can generate code for your package constants if it can find them in your ALL_IDENTIFIERS dictionary view.如果 jOOQ 可以在您的ALL_IDENTIFIERS字典视图中找到它们,它可以为您的包常量生成代码。 That's only the case if you enable PLSCOPE_SETTINGS when compiling your packages, eg using:只有在编译包时启用PLSCOPE_SETTINGS才会出现这种情况,例如使用:

ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL'

With that in place, jOOQ will generate expressions for your package constants, which you can use in routine calls, or other procedural logic .有了它,jOOQ 将为您的包常量生成表达式,您可以在例程调用或其他过程逻辑中使用这些表达式。

PL/Scope independence PL/范围独立性

What Simon Martinelli referred to in the comments is issue https://github.com/jOOQ/jOOQ/issues/6504 , which attempts to enable this code generation support even without the above PL/Scope setting turned on, because that's quite unreliable depending on your environment. Simon Martinelli 在评论中提到的是 issue https://github.com/jOOQ/jOOQ/issues/6504 ,即使没有打开上述 PL/Scope 设置,它也会尝试启用此代码生成支持,因为这非常不可靠,具体取决于在您的环境中。

As of jOOQ 3.15, there's no solution yet that works on any Oracle environment.从 jOOQ 3.15 开始,尚无适用于任何 Oracle 环境的解决方案。 But you could use testcontainers to generate your jOOQ code from a Docker image that has PL/Scope enabled. 但是您可以使用 testcontainers从启用了 PL/Scope 的 Docker 镜像生成您的 jOOQ 代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM