Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

PLSQL Variables

User_RI4C6May 24 2022

I am trying to get variable_name, variable_type and comment of all variables from any package (it can be for example standard package, ULT_HTTP, etc). I want to get these informations by writting an request from all_source view.
Here is what i have tried :
select regexp_substr(text, '\w(\w|#|\$){0,127}', 1, 1)variable_name,regexp_substr(text, '\w(\w|#|\$){0,127}', 1, 2) variable_type,regexp_replace(regexp_substr(text, '--\s*.+', 1, 1, 'n'), '(^--\s*|$)') commentaire,text from all_source
where type = 'PACKAGE' and regexp_like(text, '^\s*(\w(\w|#|\$){0,127})\s*+EXCEPTION|CONSTANT|INTEGER|ROW|VARCHAR2(;|(\s+:=\s+.+;))', 'n')and type not in ('SUBTYPE', 'PROCEDURE', 'FUNCTION', 'FORMAL IN');

Comments

L. Fernigrini

Consider using PL/Scope

PL/Scope Enhancements in Oracle Database 12c Release 2 (12.2) (0 Bytes)It is simpler than parsing code.

User_RI4C6

How its work I admit that I am a beginner in the world of plsql and I told myself that it is possible to do it with regexp

User_H3J7U

it can be for example standard package, ULT_HTTP
UTL_HTTP Constants

L. Fernigrini

undefined (0 Bytes)You need to set some session settings like this:

ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL, STATEMENTS:ALL';

Then compile the package, and then query the dictionary tables being populated when you compile PL/SQL and have set PLSCOPE settings.
In the article I mentioned there is an example :
image.pnghere you would see that variable L_NUM and L_STR are declared on lunes 6 and 7, and that they reference the NUMBER and CHARACTER datatypes. You can modify the query in the example to filter only "VARIABLE" as TYPE; "DECLARATION" as USAGE and then get the associated REFERENCE row to get the datatype.

L. Fernigrini

Poster mentioned ANY package, documentation exists only for Oracle provided packages.

User_RI4C6

Wow very cool, Thank you very much for the help.!

1 - 6

Post Details

Added on May 24 2022
6 comments
240 views