Aleks
Aleks

Reputation: 410

PLS/QL : Nasty cursor error

I need a hand for a PL/SQL. Indeed, i can't figure out why Oracle doesn't want to accept this code :

set serveroutput on;
CREATE OR REPLACE PROCEDURE route (gagnant VARCHAR2) IS

CURSOR perdants IS SELECT NPerdant FROM RENCONTRE WHERE NGagnant = gagnant;

BEGIN
        FOR perdant IN perdants
        LOOP
                dbms.output.put_line(gagnant || ' bats ' || perdants.nperdant);
                route (perdants.nperdant);
        END LOOP;
END;
/

This is the result of the show errors command :

LINE/COL     ERROR
10/17    PL/SQL: Statement ignored
10/70    PLS-00225: référence de sous-programme ou de curseur 'PERDANTS' e st hors étendue
11/17    PL/SQL: Statement ignored
11/33    PLS-00225: référence de sous-programme ou de curseur 'PERDANTS' e st hors étendue

So it tells me that it can't acces the perdants cursor because of a range problem. But I can't see why.

Upvotes: 0

Views: 593

Answers (2)

Nick Krasnov
Nick Krasnov

Reputation: 27251

Here is the problematic places:

First:

FOR perdant IN perdants
LOOP
   dbms.output.put_line(gagnant || ' bats ' || perdants.nperdant);
    route (perdants.nperdant);
END LOOP;

Your loop variable is perdant not perdants, so you should rewrite perdants.nperdant as perdant.nperdant.

Second:

dbms.output.put_line(...);

The package name is dbms_output.

Upvotes: 2

Luke Woodward
Luke Woodward

Reputation: 64959

I think you want to use perdant.nperdant (without the s) instead of perdants.nperdant. Otherwise you're not using the loop variable perdant.

Upvotes: 1

Related Questions