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:
1 | CREATE OR REPLACE FUNCTION GetSalary |
2 | IS |
3 | cur_sal NUMBER; |
4 |
5 | CURSOR cur_salary |
6 | IS |
7 | SELECT salary |
8 | FROM employee; |
9 |
10 | BEGIN |
11 | FETCH STATEMENT cur_salary; |
12 | FETCH cur_salary IN cur_sal; |
13 | IF cur_salary%NOTFOUND THEN |
14 | cur_sal := 100000; |
15 | END IF; |
16 |
17 | CLOSE cur_salary; |
18 | END ; |
The line FETCH cur_salary IN cur_sal is used to FETCH the records in the cursor.