Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PLS-00201: identifier 'CURSOR' must be declaredCompilation failed

amjadham77QNov 24 2021 — edited Nov 24 2021

hi guys ...
I'm having a problem creating this procedure and I can't solve this problem
Do you have a solution or any tips?
--------------------------------------------------------------------------------
Goal from procedure:
to print employee name and grades based on salary.
--------------------------------------------------------------------------------
Problem/Error:
Compilation failed,line 13 (13:52:34)
PLS-00201: identifier 'CURSOR' must be declaredCompilation failed,line 13 (13:52:34)
PL/SQL: SQL Statement ignoredCompilation failed,line 41 (13:52:34)
PLS-00201: identifier 'CURSOR' must be declaredCompilation failed,line 41 (13:52:34)
PL/SQL: SQL Statement ignored
--------------------------------------------------------------------------------
Code/sql pl:
create or replace PROCEDURE printgrades is
CURSOR nasa IS SELECT ename, sal FROM emp;
r_nasa nasa%ROWTYPE;
BEGIN
--open cursor to allocate memory for cursor
IF NOT nasa%ISOPEN THEN
OPEN CURSOR;
END IF;
--start point of looping on the cursor
LOOP
--fetching data from cursor
FETCH nasa INTO r_nasa;
DBMS_OUTPUT.PUT(r_nasa.ename || ', ');
--classification of employees according to salary
CASE
WHEN r_nasa.sal>1 AND r_nasa.sal<=1000 THEN
DBMS_OUTPUT.PUT('LESS THAN 1000');
WHEN r_nasa.sal>1000 AND r_nasa.sal<=2000 THEN
DBMS_OUTPUT.PUT('BETWEEN 1000 & 2000');
WHEN r_nasa.sal>2000 AND r_nasa.sal<=3000 THEN
DBMS_OUTPUT.PUT('BETWEEN 2000 & 3000');
WHEN r_nasa.sal>3000 THEN
DBMS_OUTPUT.PUT('GREATER THAN 3000');
ELSE
DBMS_OUTPUT.PUT('Invailed salary value!');
END CASE;
--condition to prevent infinite looping
EXIT WHEN nasa%NOTFOUND;
--end point of looping on the cursor
END LOOP;
--close cursor to release the allocated memory
IF nasa%ISOPEN THEN
CLOSE CURSOR;
END IF;
END printgrades;​
------------------------------------------------------------------------
SharedScreenshot.jpgSharedScreenshot2.jpgSharedScreenshot3.jpg

This post has been answered by BEDE on Nov 24 2021
Jump to Answer
Comments
Post Details
Added on Nov 24 2021
7 comments
1,145 views