# CodeXpert - why reports CURSOR violations?

**URL:** <https://forums.toadworld.com/t/codexpert-why-reports-cursor-violations/11105>\
**Category:** Toad for Oracle & DevOps Toolkit\
**Created:** [April 3, 2012, 9:50am UTC](https://forums.toadworld.com/t/codexpert-why-reports-cursor-violations/11105 "2012-04-03T09:50:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasSchmid](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AndreasSchmid](https://forums.toadworld.com/u/AndreasSchmid)\
**Post date:** [April 3, 2012, 9:50am UTC](https://forums.toadworld.com/t/codexpert-why-reports-cursor-violations/11105/1 "2012-04-03T09:50:32Z")

</div>

Hello,

I am wondering why I get following CURSOR violations on the simple code example below:

- three times “Cursor - Ensure that any local cursors you are referencing have actually been opened”  
\*\* (18,16)  
\*\* (20,13)  
\*\* (22,19)
- once “Cursor - Confirm that the cursor you are referencing has been opened”  
\*\* (12,14)

{code}  
CREATE OR REPLACE PACKAGE BODY PKG\_TEST  
AS  
CURSOR cursor1  
IS  
SELECT 1 FROM DUAL;

PROCEDURE PROC\_TEST  
IS  
val\_i NUMBER (10);  
BEGIN  
IF NOT cursor1%ISOPEN  
THEN  
OPEN cursor1;  
END IF;

```
  LOOP
     FETCH cursor1 INTO val_i;

     IF cursor1%NOTFOUND
     THEN
        CLOSE cursor1;

        EXIT;
     END IF;
  /* ... some further code ... */
  END LOOP;

```

END PROC\_TEST;  
END PKG\_TEST;  
/  
{code}

Can anybody help me figuring out this?

IMHO it is necessary to ask here if the cursor is already opened due to its declarations in package scope and the possible exception for opening an already open cursor.  
For sure one can fix this situation if the cursor is moved to procedure scope but that is not possible because it is reused at another place (this short example just does not contain this).

I am using Toad 9.7.2.5 …

I very much appreciate your help, thank you.

---

<div class="post-metadata">

**Author:** ![AndreasSchmid](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AndreasSchmid](https://forums.toadworld.com/u/AndreasSchmid)\
**Post date:** [April 10, 2012, 6:26am UTC](https://forums.toadworld.com/t/codexpert-why-reports-cursor-violations/11105/2 "2012-04-10T06:26:37Z")

</div>

Can anyone tell me if the above described problem still occurs the newest version (11.0) by using the provided code example?

Thank you very much …

---

<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:** [April 18, 2012, 2:10pm UTC](https://forums.toadworld.com/t/codexpert-why-reports-cursor-violations/11105/3 "2012-04-18T14:10:06Z")

</div>

Hello Andreas,

A few code analysis rules use older legacy code which often has flaws. We are in the process of replacing old code over time. We already did such for the majority of the rules by introducing XPath expressions. It will sure take several months to finish all kinds of analysis, including cursor analysis. Thanks for understanding, we do the best we can.

Andre

---

<div class="post-metadata">

**Author:** ![AndreasSchmid](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AndreasSchmid](https://forums.toadworld.com/u/AndreasSchmid)\
**Post date:** [April 23, 2012, 2:43am UTC](https://forums.toadworld.com/t/codexpert-why-reports-cursor-violations/11105/4 "2012-04-23T02:43:44Z")

</div>

Hi Andre,

thanks for your feedback. It is, though, not clear for me if the above false positive is fixed in 11.5 or not?

Cheers,  
Andreas
