有关 PL/SQL 包级记录类型的元数据
假设您有一个定义了 RECORD
类型的 PL/SQL 包:
CREATE OR REPLACE PACKAGE TEST_PACKAGE AS
TYPE PERSON_RECORD_TYPE IS RECORD
(
first_name VARCHAR2(1000),
last_name VARCHAR2(1000)
);
END;
有没有办法获取 TEST_PACKAGE.PERSON_RECORD_TYPE
中包含的字段列表?例如,是否有包含此信息的 ALL_*
视图?
我对模式级记录类型不感兴趣,只对包级记录类型感兴趣。
Suppose you have a PL/SQL package with a RECORD
type defined:
CREATE OR REPLACE PACKAGE TEST_PACKAGE AS
TYPE PERSON_RECORD_TYPE IS RECORD
(
first_name VARCHAR2(1000),
last_name VARCHAR2(1000)
);
END;
Is there any way to obtain a list of fields contained within TEST_PACKAGE.PERSON_RECORD_TYPE
? For example, are there any ALL_*
views with this information?
I am not interested in schema-level record types, only package-level record types.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 PERSON_RECORD_TYPE 用作某些过程或函数的参数或结果类型,则可以查询 ALL_ARGUMENTS。信息在那里进行了一点加密(记录和集合的多级封装的层次结构在 POSITION、SEQUENCE 和 DATA_LEVEL 列中进行编码),但它确实存在。
我不认为这样的问题指向错误的架构。对于自动 PLSQL 代码生成,这是完全合法的请求,不幸的是 PLSQL 语言支持非常弱。
If PERSON_RECORD_TYPE is used as argument or result type of some procedure or function, you can query ALL_ARGUMENTS. The information is little bit encrypted there (the hierarchy of multilevel encapsulation of records and collections is encoded in POSITION,SEQUENCE and DATA_LEVEL columns), however it is present.
I don't think such a question points to wrong architecture. For automatic PLSQL code generation this is completely legitimate request, unfortunately with very weak PLSQL language support.
Oracle 18c 之后的解决方案
我认为这在 18c 之前不起作用(如果我错了,请纠正我),但现在我们可以查询
ALL_PLSQL_TYPE_ATTRS
视图:获取某些内容像这样:
Oracle 18c 之前的解决方案
jOOQ 的代码生成器内部使用以下查询来可靠地查找所有包级别
PL/SQL RECORD
类型:在您的情况下,结果将类似于:
当前限制:
ALL_ARGUMENTS
字典视图继承的限制。%ROWTYPE
类型未正确返回,因为未从TYPE_NAME
/TYPE_SUBNAME
列引用行类型。更多信息请点击这里:
https:// blog.jooq.org/2016/11/08/use-jooq-to-read-write-oracle-plsql-record-types
Solution after Oracle 18c
I think this didn't work prior to 18c (correct me if I'm wrong), but now we can query the
ALL_PLSQL_TYPE_ATTRS
view:To get something like this:
Solution prior to Oracle 18c
jOOQ's code generator internally uses the following query to reliably find all package level
PL/SQL RECORD
types:In your case, the result will be something like:
Current limitations:
ALL_ARGUMENTS
dictionary view in the query.%ROWTYPE
types are not returned correctly because the row type is not referenced from theTYPE_NAME
/TYPE_SUBNAME
columns.More information here:
https://blog.jooq.org/2016/11/08/use-jooq-to-read-write-oracle-plsql-record-types
以下是一些有关从包代码中检索信息的类似问题。
从数据字典中查找包全局变量
从 Oracle 获取包方法和参数
我认为这是一个与第一个类似的问题。您无法通过视图访问这些字段。有解析源文本解决方案,它很丑陋,或者您可能需要解决此问题。
不管怎样,如果你需要这个,我认为你的架构有问题。
Here are some similar questions about retrieving information from package code.
Find package global variables from data dictionary
Get Package Methods and Parameters from Oracle
I see this as a similar problem like first one. You cannot acces those fields via a view. There is the parse source text solution, which is ugly, or you may need an workaround to this.
Anyway, I think it is something wrong in your architecture if you need this.