A Cursors is Pointer to memory location on database server , and DBMS uses to process a SQL query.
An example of cursor
DECLARE
CURSOR student_cur IS
SELECT student_name, student_id FROM student;
– declare record variable that represents a row fetched from the studentt table
student_rec student_cur%ROWTYPE;
BEGIN
– open the explicit cursor and use it to fetch data into student_rec
OPEN student_cur;
LOOP
FETCH student_cur INTO student_rec;
EXIT WHEN student_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(student_rec.student_name || ‘ , ‘ || student_rec.student_id);
END LOOP;
END;
Written by: Mohammed Alaslani
Advertisement