As you've probably gathered, the code below isn't real - but it highlights my point.
PROCEDURE Do_Some_Dynamic_Stuff (
sql_ IN VARCHAR2 )
IS
cur_ INTEGER := Dbms_Sql.Open_Cursor;
res_ NUMBER;
BEGIN
Dbms_Sql.Parse (cur_, sql_, dbms_sql.native);
res_ := Dbms_Sql.Execute (cur_);
-- ...
-- > use cursor cur_ in this code to achieve "stuff"
-- > value `res_` never required by the program
-- > end program successfully without errors
-- ...
END Do_Some_Dynamic_Stuff;
When compiled, the above procedure will produce a compiler warning: Hint: Value assigned to 'res_' never used
.
I know what the warning means, and it makes sense to have the issue highlighted because it can help tidy up old code when variables defined in the DECLARE
(or IS
) block become redundant/unused.
I have seen similar questions asked on SO, but the answers suggest toning down the Warning levels in Oracle. The problem is that:
The point is that in the above scenario, the res_
variable is necessary to allow the code to compile, but is unnecessary in the context of the PROCEDURE
. I just want a way to suppress the message in this instance of the warning
Of course, one way to work around the problem is to add a pointless line of code such as:
Dbms_Output.Put_Line ('avoid compiler warning: ' || res_);
But that's hardly a very eloquent solution, and anyway it clogs up your debug output etc. etc. So I'm just wondering if someone out there may have a pretty solution to this little bug bear.
If you are using pl/sql developer, you might want to try this (excerpt from PL/SQL Developer 12.0 User’s Guide):
To suppress a warning you can add a -- Ignore comment after the line that produces the hint. This works both for Oracle compilation warnings described in this chapter and for PL/SQL Developer hints as described in chapter 20.9. You can add additional text after -- Ignore to describe the situation
Just note that these comments are not portable to other IDE's.