1 FOR b IN (SELECT *
2 FROM sometable)
3 LOOP
4 <<do something b.somevalue>>
5 END LOOP;
1FOR record_name IN cursor_name
2LOOP
3 statement1;
4 statement2;
5 . . .
6END LOOP;
1/*Is abit complex*/
2
3set serveroutput on ;
4Declare
5departmentName departments.department_name %Type;
6countryName countries.country_name%Type;
7countryName2 countries.country_name%Type;
8cursor info2 is
9select countries.country_name from departments,countries,locations where departments.location_id=locations.location_id and locations.country_id=countries.country_id GROUP by countries.country_name;
10
11cursor info is
12select departments.department_name,countries.country_name from departments,countries,locations where departments.location_id=locations.location_id and locations.country_id=countries.country_id;
13begin
14for rec2 in info2
15loop
16countryName:= rec2.country_name;
17 dbms_output.put_line('Deparments in the ' || countryName ||' :' ||chr(13));
18 for rec in info
19 loop
20 departmentName:= rec.department_name;
21 countryName2:= rec.country_name;
22 if countryName2=countryName then
23 dbms_output.put_line(' '||departmentName);
24 end if;
25 end loop;
26
27 dbms_output.put_line('------------------------------------');
28end loop;
29end;
30