declare
v_country_name wf_countries.country_name%type:='United States of America';
v_lowest_elevation wf_countries.lowest_elevation%type;
v_highest_elevation wf_countries.highest_elevation%type;
begin
select lowest_elevation, highest_elevation into v_lowest_elevation, v_highest_elevation
from wf_countries
where country_name=v_country_name;
dbms_output.put_line('the lowest elevation in '||v_country_name||' is '||v_lowest_elevation||' and the highest elevation is '||v_highest_elevation);
end;


declare
v_max_deptno new_depts.department_id%type;
v_dept_name new_depts.department_name%type:='A new Department';
v_dept_id new_depts.department_id%type;
begin
select max(department_id) into v_max_deptno
from new_depts;
dbms_output.put_line('the maximim department id is :'||v_max_deptno);
end;


declare
v_max_deptno new_depts.department_id%type;
v_dept_name new_depts.department_name%type:='A new Department';
v_dept_id new_depts.department_id%type;
begin
select max(department_id) into v_max_deptno
from new_depts;
dbms_output.put_line('the maximim department id is :'||v_max_deptno);
v_dept_id:=v_max_deptno+10;
dbms_output.put_line('the maximim department id is :'||v_dept_id);
insert into new_depts ()
end;


declare
v_pop wf_countries.population%type;
v_c_id wf_countries.country_id%type:=44;
begin
select population into v_pop from wf_countries where country_id=v_c_id;
if v_pop>1000000000 then dbms_output.put_line('population greater then 1 bilion');
else dbms_output.put_line('population smaller then 1 bilion');
end if;
end;

declare
v_curr wf_countries.CURRENCY_CODE%type:='USD';
v_c_no pls_integer;
begin
select count(*) into v_c_no from wf_countries where CURRENCY_CODE=v_curr;
case 
when v_c_no>20 then   dbms_output.put_line('more then 20 countries');
when (v_c_no<=20 and v_c_no>=10) then dbms_output.put_line('between 10 and 20 countries');
when v_c_no<10 then dbms_output.put_line('fewer then 10 countries');
end case;
end;

declare
v_curn wf_currencies.currency_name%type:=:curr_name;
v_curc wf_countries.CURRENCY_CODE%type;
v_c_no pls_integer;
begin
select count(*) into v_c_no from wf_countries c join wf_currencies c1 on c.currency_code=c1.currency_code where c1.CURRENCY_name=v_curn;
case 
when v_c_no>20 then   dbms_output.put_line('more then 20 countries');
when (v_c_no<=20 and v_c_no>=10) then dbms_output.put_line('between 10 and 20 countries');
when v_c_no<10 then dbms_output.put_line('fewer then 10 countries');
end case;
end;

declare
v_c_n wf_countries.country_name%type;
v_c_id wf_countries.country_id%type;
v_1 pls_integer:=1;
begin
loop 
select country_name, country_id into v_c_n, v_c_id from wf_countries where country_id=v_1;
dbms_output.put_line('id: '||v_c_id||' name: '||v_c_n);
v_1:=v_1+1;
exit when v_1>3;
end loop;
end;


declare
v_c_n wf_countries.country_name%type;
v_c_id wf_countries.country_id%type;
v_1 pls_integer:=51;
begin
while v_1<=55
loop
select country_name, country_id into v_c_n, v_c_id from wf_countries where country_id=v_1;
dbms_output.put_line('id: '||v_c_id||' name: '||v_c_n);
v_1:=v_1+1;
end loop;
end;

declare
v_c_n wf_countries.country_name%type;
v_c_id wf_countries.country_id%type;
begin
for v_1 in reverse 51..55
loop
select country_name, country_id into v_c_n, v_c_id from wf_countries where country_id=v_1;
dbms_output.put_line('id: '||v_c_id||' name: '||v_c_n);
end loop;
end;

begin
for i in 60..65 loop
for j in 100..110 loop
dbms_output.put_line(i||'-'||j);
end loop;
end loop;
end; 

declare
v pls_integer;
begin
for i in 60..65 loop
for j in 100..110 loop
v:=i+j;
dbms_output.put_line(v);
end loop;
exit when v>172;
end loop;
end; 

declare
v pls_integer;
begin
<<outer>>
for i in 60..65 loop
<<inner>> 
for j in 100..110 loop
exit outer when v>=172;
v:=i+j;
dbms_output.put_line(v);
end loop inner;
end loop outer;
end; 


declare
cursor wf_currencies_cur
is
select currency_code, currency_name
from wf_currencies
order by currency_name;
begin

end;

declare
cursor wf_currencies_cur
is
select currency_code, currency_name
from wf_currencies
order by currency_name;
v_cur_c wf_currencies.currency_code%type;
v_cur_n wf_currencies.currency_name%type;
begin
open wf_currencies_cur;
fetch wf_currencies_cur into v_cur_c, v_cur_n;

end;

declare
cursor wf_currencies_cur
is
select currency_code, currency_name
from wf_currencies
order by currency_name;
v_cur_c wf_currencies.currency_code%type;
v_cur_n wf_currencies.currency_name%type;
begin
open wf_currencies_cur;
fetch wf_currencies_cur into v_cur_c, v_cur_n;
dbms_output.put_line(v_cur_c||' '||v_cur_n);
close wf_currencies_cur;
end;

declare
cursor wf_currencies_cur
is
select currency_code, currency_name
from wf_currencies
order by currency_name;
v_cur_c wf_currencies.currency_code%type;
v_cur_n wf_currencies.currency_name%type;
begin
open wf_currencies_cur;
loop
fetch wf_currencies_cur into v_cur_c, v_cur_n;
exit when wf_currencies_cur%notfound;
dbms_output.put_line(v_cur_c||' '||v_cur_n);
end loop;
dbms_output.put_line(wf_currencies_cur%rowcount);
close wf_currencies_cur;
end;

declare
cursor wf_countries_cur
is
select country_name, national_holiday_date, national_holiday_name
from wf_countries
where region_id=5;
v_c_n wf_countries.country_name%type;
v_h_d wf_countries.national_holiday_date%type;
v_h_n wf_countries.national_holiday_name%type;
begin
open wf_countries_cur;
loop
fetch wf_countries_cur into v_c_n,v_h_d,v_h_n;
exit when wf_countries_cur%notfound;
dbms_output.put_line(v_c_n||' '||v_h_d||' '||v_h_n);
end loop;
close wf_countries_cur;
end;

declare
cursor emp_cur is
select first_name,last_name,job_id,salary
from employees
order by salary desc;
begin
for emp_cur_rec in emp_cur
loop
exit when emp_cur%rowcount>6;
dbms_output.put_line(emp_cur_rec.first_name||' '||emp_cur_rec.last_name||' '||emp_cur_rec.job_id||' '||emp_cur_rec.salary);
end loop;
end;

declare
cursor emp_cur is
select first_name,last_name,job_id,salary
from employees
order by salary desc;
emp_cur_rec emp_cur%rowtype;
begin
open emp_cur;
loop
fetch emp_cur into emp_cur_rec;
exit when emp_cur%rowcount>6;
dbms_output.put_line(emp_cur_rec.first_name||' '||emp_cur_rec.last_name||' '||emp_cur_rec.job_id||' '||emp_cur_rec.salary);
end loop;
close emp_cur;
end;

declare
cursor emp_cur is
select first_name,last_name,job_id,salary
from employees
order by salary desc;
emp_cur_rec emp_cur%rowtype;
begin
open emp_cur;
loop
fetch emp_cur into emp_cur_rec;
exit when emp_cur%notfound;
dbms_output.put_line(emp_cur_rec.first_name||' '||emp_cur_rec.last_name||' '||emp_cur_rec.job_id||' '||emp_cur_rec.salary);
end loop;
close emp_cur;
end;

declare
cursor wf_countries_cur
is
select country_name, national_holiday_date, national_holiday_name
from wf_countries
where region_id=5;
begin
for wf_countries_rec in wf_countries_cur
loop
exit when wf_countries_cur%notfound;
dbms_output.put_line(wf_countries_rec.country_name||' '||wf_countries_rec.national_holiday_date||' '||wf_countries_rec.national_holiday_name);
end loop;
end;

begin
for wf_countries_rec in (select country_name, national_holiday_date, national_holiday_name
from wf_countries
where region_id=5)
loop
dbms_output.put_line(wf_countries_rec.country_name||' '||wf_countries_rec.national_holiday_date||' '||wf_countries_rec.national_holiday_name);
end loop;
end;