Please suppose you have an Oracle PL/SQL package of about 200,000 rows of code.
Is there any fast way to detect variables declared, but not used in the package?
Thank you in advance for your kind help.
EDIT (April 7th, 2014): I am using Oracle 10G.
EDIT: I am looking for a pure PL/SQL solution.
So finding and fixing unused variables is just a housekeeping exercise and won't improve the performance of the package. In other words, the simplest solution would be to do nothing.
If you're worried about unused variables anyway, you might be able to find them just by parsing the package source with command-line tools such as
grep
,sort
anduniq
(especially if they follow a coding standard such as starting all variables withv_
).Set your session to report all warnings:
then compile your code. If the compilation indicates that there are errors, as in you get something like the following:
display any errors:
If you have any unreferenced variables they should be mentioned in the list of errors. Alternatively, use a tool like PL/SQL Developer which automatically shows you these errors following a compile.
Share and enjoy.
The following only applies to 11g R2. It looks like PL/Scope has become available in 11g R1.
You won't get information about unused variables with
PLSQL_WARNINGS='ENABLE:ALL'
:As you can see the only reported warning is not related to the unused variables at all. Instead PL/Scope has to be used.
The following example has bee derived from Oracle 11g – Generating PL/SQL Compiler Warnings (Java style) using PL/Scope:
The script
plsql-unused-variables.sql
is just a cut and paste from the blog post mentioned above. Because I found it useful I have also made the script available in Bitbucket.