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.
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.
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
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.