The basic syntax is the keyword cursor followed by the cursor_name and then the select statement.
CURSOR<cursor_name>IS Select_statement;
Cursor_name - The name of the cursor.
Select statement - Selecting the name of the variable.
In the declaration block, two variables I_dept_name and I_dept_id are to be declared to hold the dept id and dept name values. And, then declare a cursor cur_get_department to select the dept_name and dept_id from the department where dept_id is equal to 1. Open a PLSQL Cursor in the execution section using the name. This will assign an area in memory for the cursor, parse and execute the query to get the desired output and then issue the fetch to get the first row from the result set. The number and type of variables should match the select columns. For instance, I_dept_id should match the type of dept_id and the I_dept_name should match the type of dept_name. If there are two columns in the select statement, there should be only two variables to fetch, otherwise oracle gives an error and then close the cursor.
One advantage of using this cursor is that even if there is no data found, it won't show up any error. And, oracle gives cursor attributes in order to handle it. For example, fetching a single row from the department table. If we fetch more than one row like fetching the emp_id and emp_sal, it can be manipulated by 0.10.
It declares a record based on the cursor column and can be accessed using dot notations.
If the cursor is said to be true, it will fetch the statements and returns at least one row. It doesn't return a statement, if it is said to be false.
If the cursor is said to be true, it will fetch the statements and doesn't return a row. It returns at least one row, if it said to be false.
In the program, if the cursor is already open, it returns true. Otherwise it returns false, if the cursor is not opened in the program.