I work in vs code(I installed the SQL developer extension) and i keep having the same error while using explicit cursor, I don’t understand what’s wrong:
Error starting at line : 2 in command –
DECLARE
CURSOR a_cursor IS
SELECT id_angajat, nume, prenume, data_angajarii
FROM angajati
WHERE EXTRACT(YEAR FROM data_angajarii) = 2020;
a_record angajati%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Lista angajatilor: ‘);
OPEN a_cursor;
IF a_cursor%FOUND THEN
LOOP
FETCH a_cursor INTO a_record;
EXIT WHEN a_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (a_record.id_angajat || ‘, ‘ || a_record.nume || ‘, ‘ || a_record.prenume || ‘, ‘ || a_record.data_angajarii);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE (‘Nu s-au gasit angajati’);
END IF;
CLOSE a_cursor;
END;
Error report –
Here is the code (it should display the employees who were hired in 2020, and if they are not found, display a message):
SET SERVEROUTPUT ON
DECLARE
CURSOR a_cursor IS
SELECT id_angajat, nume, prenume, data_angajarii
FROM angajati
WHERE EXTRACT(YEAR FROM data_angajarii) = 2020;
a_record angajati%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Lista angajatilor: ‘);
OPEN a_cursor;
IF a_cursor%FOUND THEN
LOOP
FETCH a_cursor INTO a_record;
EXIT WHEN a_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (a_record.id_angajat || ‘, ‘ || a_record.nume || ‘, ‘ || a_record.prenume || ‘, ‘ || a_record.data_angajarii);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE (‘Nu s-au gasit angajati’);
END IF;
CLOSE a_cursor;
END;
/
I thought it was a problem with the cursor, that’s why I tested if it opens. Does it have anything to do with the fact that I use vs code? If so, how could I change the code?
Moise Miruna Ilinca is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.