# Code Analysis: Unused variable not detected

**URL:** <https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481>\
**Category:** Toad for Oracle - Beta\
**Created:** [October 9, 2016, 11:05pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481 "2016-10-09T23:05:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterLang](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PeterLang](https://forums.toadworld.com/u/PeterLang)\
**Post date:** [October 9, 2016, 11:05pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/1 "2016-10-09T23:05:28Z")

</div>

I don’t really know what happens here, hope you can reproduce it.

Paste this code into a new editor tab:

CREATE OR REPLACE PROCEDURE test\_proc AS  
TYPE number\_tab IS TABLE OF NUMBER(12);  
unused\_variable PLS\_INTEGER;  
BEGIN  
IF ( 1 MEMBER OF NEW number\_tab() ) THEN  
NULL;  
END IF;  
END test\_proc;

1. The unused variable is not detected.

2. Interesting add-on:

Now compile the procedure and change something in the code to trigger Code Analysis.  
Rule 2131 (Use CONSTANT keyword wherever possible) appears.

---

<div class="post-metadata">

**Author:** ![avergison](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/avergison/32/66_2.png) [@avergison](https://forums.toadworld.com/u/avergison)\
**Post date:** [October 10, 2016, 9:41am UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/2 "2016-10-10T09:41:45Z")

</div>

A few rules still use old legacy code which will not process post 9i code. Rule 6405 (Avoid defining variables that are not referenced inside the program) is one of them. If you change 1 MEMBER OF NEW number\_tab() by just 1 then the 6405 will pop up. This is in the pipeline but on longer term.

About 2131 this rule currently also fires whenever the variable (constant) is not referred to at all, it fires when no assignments are found without looking that the var is referenced. This needs fixing. (QP-1875)

Thanks,  
Andre

---

<div class="post-metadata">

**Author:** ![PeterLang](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PeterLang](https://forums.toadworld.com/u/PeterLang)\
**Post date:** [October 10, 2016, 10:32pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/3 "2016-10-10T22:32:18Z")

</div>

Thanks for your answer!

I totally understand the part about legacy code, but I am not sure what you mean by “change by just 1”?

That 2131 shows for unused variables is a minor issue, but I’m really curious why it does not show unless I compile the unit and change something afterwards?

This does not seem to be related to the other issue. When I paste the following code, the warning is only displayed after compiling the unit. Once it has been compiled, warnings are displayed immediately when another unused/constant variable is introduced:

CREATE OR REPLACE PROCEDURE test\_proc AS  
my\_constant PLS\_INTEGER;  
my\_variable PLS\_INTEGER;  
BEGIN  
my\_variable := my\_constant;  
END test\_proc;

---

<div class="post-metadata">

**Author:** ![avergison](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/avergison/32/66_2.png) [@avergison](https://forums.toadworld.com/u/avergison)\
**Post date:** [October 11, 2016, 2:59am UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/4 "2016-10-11T02:59:40Z")

</div>

Sorry, I meant

IF ( 1 ) THEN

which does not compile, actually meaning

IF ( true ) THEN

🙂

About the 2131 issue, I recompiled and then added a space next to another space, it does not show up here. What did you actually do? Does it appear near the unused\_variable declaration?

---

<div class="post-metadata">

**Author:** ![PeterLang](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@PeterLang](https://forums.toadworld.com/u/PeterLang)\
**Post date:** [October 11, 2016, 4:59am UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/5 "2016-10-11T04:59:32Z")

</div>

It looks like this after pasting:

![01.png](https://global.discourse-cdn.com/quest/original/2X/7/763d161a30ca65bc9d92f301caab7d213df48a9f.png)

After first time compiling (tab header has changed):

![02.png](https://global.discourse-cdn.com/quest/original/2X/f/f054bd7c937d27f3cb49bdf17722493d67f0c3f8.png)

After appending a space (warnings are displayed):

![03.png](https://global.discourse-cdn.com/quest/original/2X/9/905163b7b61b706b98f3266909ad80a352fd7c68.png)

---

<div class="post-metadata">

**Author:** ![kevin.cook](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@kevin.cook](https://forums.toadworld.com/u/kevin.cook)\
**Post date:** [March 1, 2019, 6:59pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/6 "2019-03-01T18:59:25Z")

</div>

I am lost!! I am using Toad for Oracle 13.0.0.80 and I am unable to get it to recognize variables that are not used. Is there a resolution to this?

---

<div class="post-metadata">

**Author:** ![jbowman](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/jbowman/32/22_2.png) [@jbowman](https://forums.toadworld.com/u/jbowman)\
**Post date:** [March 1, 2019, 7:35pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/7 "2019-03-01T19:35:15Z")

</div>

Hi Kevin,

We had found an issue in our parser when processing certain specific rules. While Rule 6405 isn’t included in the list of problematic rules, the issue sometimes prevented the completion of the Code Analysis scan process. We temporarily disabled the problematic rules for builds that were released earlier this week until the underlying issue can be fixed. Can you try updating to the latest beta build and see if that solves your problem?

Let us know if you continue to experience problems with it.

Thanks,

-John

---

<div class="post-metadata">

**Author:** ![jbowman](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/jbowman/32/22_2.png) [@jbowman](https://forums.toadworld.com/u/jbowman)\
**Post date:** [March 1, 2019, 8:07pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/8 "2019-03-01T20:07:24Z")

</div>

Hi Kevin,

I just realized you mentioned 13.0.0.80, and since this was posted in the Beta forum, I had read that as 13.2.0.80 which was released last week. I can reproduce your issue in Toad 13.0 and Toad 13.1. This issue was fixed in Toad Beta 13.2.0.18; however in order to use the Beta product, you’ll need to first upgrade your GA version of Toad to the current version, which is 13.1.0.78.

-John

---

<div class="post-metadata">

**Author:** ![avergison](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/avergison/32/66_2.png) [@avergison](https://forums.toadworld.com/u/avergison)\
**Post date:** [August 2, 2020, 8:10pm UTC](https://forums.toadworld.com/t/code-analysis-unused-variable-not-detected/38481/9 "2020-08-02T20:10:51Z")

</div>

Please check out next (or next next) beta, rule 6405 should work quite a bit better.

Thanks,  
Andre
