FETCH statement in Oracle PLSQL is used to access the records from the CURSOR which has been previously opened.
Oracle PSQL Syntax to use FETCH CURSOR statement is:
FETCH cursor_name INTO
Let’s understand, how to use FETCH Statement in a cursor from the help of the below PLSQL function:
CREATE OR REPLACE FUNCTION GetSalary IS cur_sal NUMBER; CURSOR cur_salary IS SELECT salary FROM employee; BEGIN FETCH STATEMENT cur_salary; FETCH cur_salary IN cur_sal; IF cur_salary%NOTFOUND THEN cur_sal := 100000; END IF; CLOSE cur_salary; END;
The line FETCH cur_salary IN cur_sal is used to FETCH the records in the cursor.