0 votes
in PL/SQL by
Explain what Is A Cursor For Loop And How Does It Differ From An Explicit Cursor?

1 Answer

0 votes
by

Cursor FOR loop is a shortcut to use explicit cursors. It does not require explicit opening, fetching, and closing of the cursor. In other words, the cursor FOR loop implicitly opens the cursor, fetches the record, and closes the cursor. In the cursor FOR loop, the cursor is defined and its attributes are checked within the processing of the FOR loop. The records are also implicitly defined within the loop, as shown in the following code:

Declare 

v_increment number(10.2); 

Cursor em P_cursor IS 

Select emp_code. emp_name. emp_salary from t_employeeS; 

Begin

FOR emp_record IN em p_cursor 

v_increment emp_record.emp_salary • 0.20 

D13MS_OUTPUT.PUTLINE 

(emp_FREOFthent_COOR 11 'Ilemp_record.emp_name II " II v_increment); 

END LOOP; 

END;

It is also possible to use a cursor FOR loop with a subquery, where the cursor name is not defined. In this case, the attributes of the cursor cannot be checked as no explicit cursor name is defined.

Related questions

0 votes
asked Mar 13, 2021 in PL/SQL by rajeshsharma
0 votes
+1 vote
asked Mar 7, 2021 in PL/SQL by SakshiSharma
...