Answers for "cursor assignment in pl sql"

SQL
3

pl sql implicit cursor

FOR b IN (SELECT * 
              FROM sometable)
  LOOP
    <<do something   b.somevalue>>
  END LOOP;
Posted by: Guest on May-25-2021
0

pl sql cursor

/*Is abit complex*/

set serveroutput on ; 
Declare 
departmentName departments.department_name %Type;
countryName countries.country_name%Type;
countryName2 countries.country_name%Type;
cursor info2 is
select 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; 

cursor info is
select  departments.department_name,countries.country_name from departments,countries,locations where departments.location_id=locations.location_id and locations.country_id=countries.country_id; 
begin 
for rec2 in info2
loop 
countryName:= rec2.country_name;
 dbms_output.put_line('Deparments in the ' || countryName ||' :' ||chr(13));
  for rec in info
  loop 
    departmentName:= rec.department_name;
    countryName2:= rec.country_name;
     if countryName2=countryName then  
        dbms_output.put_line('  '||departmentName);
     end if;
  end loop;

  dbms_output.put_line('------------------------------------');
end loop;
end;
Posted by: Guest on September-03-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language