Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Download
Standard view
Full view
of .
Add note
Save to My Library
Sync to mobile
Look up keyword
Like this
2Activity
×
0 of .
Results for:
No results containing your search query
P. 1
c0594434_section_5_part_2

c0594434_section_5_part_2

Ratings: (0)|Views: 1,026|Likes:
Published by prem_shah488

More info:

Published by: prem_shah488 on Mar 16, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See More
See less

04/05/2014

pdf

text

original

 
1. WriteaPL/SQLblocktoreadthroughrowsinthewf_countriestableforallcountriesinregion5(SouthAmericaregion).Foreachselectedcountry,displaythecountry_name,national_holiday_date,andnational_holiday_name.Usearecordstructuretoholdallthecolumnsselectedfromthewf_countriestable.DECLARECURSORwf_country_cursorISSELECT*FROMwf_countriesWHEREregion_id=5ANDnational_holiday_dateISNOTNULL;v_country_recordwf_country_cursor%ROWTYPE;BEGINOPENwf_country_cursor;LOOPFETCHwf_country_cursorINTOv_country_record;EXITWHENwf_country_cursor%NOTFOUND;DBMS_OUTPUT.PUT_LINE('Country:'||v_country_record.country_name||'NationalHoliday:'||v_country_record.national_holiday_name||'heldon:'||v_country_record.national_holiday_date);ENDLOOP;CLOSEwf_country_cursor;END;2. Forthisexercise,youusetheemployeestable.CreateaPL/SQLblockthatfetchesanddisplaysthesixemployeeswiththehighestsalary.Foreachoftheseemployees,displaythefirstname,lastname,jobidandsalary.Orderyouroutputsothattheemployeewiththehighestsalaryisdisplayedfirst.Use%ROWTYPEandtheexplicitcursorattribute%ROWCOUNT.DECLARECURSORemp_cursorISSELECT*FROMemployeesORDERBYsalaryDESC;v_emp_recordemp_cursor%ROWTYPE;BEGINOPENemp_cursor;LOOPFETCHemp_cursorINTOv_emp_record;EXITWHENemp_cursor%ROWCOUNT>6ORemp_cursor%NOTFOUND;DBMS_OUTPUT.PUT_LINE('Employee:'||v_emp_record.first_name||''||v_emp_record.last_name||',JobID:'||v_emp_record.job_id||',havingmaximumsalary:'||v_emp_record.salary);ENDLOOP;CLOSEemp_cursor;END;3. Usingthewf_countriestable,writeacursorthatreturnscountrieswithahighest_elevationgreaterthan8,000m.Foreachcountry,displaythecountry _name,highest_elevation,andclimate.UseacursorFORloop,declaringthecursorusingasubqueryintheFOR
LOOPstatement.BEGINFORv_country_recIN(SELECT*FROMwf_countriesWHEREhighest_elevation>8000)LOOPDBMS_OUTPUT.PUT_LINE('Countryname:'||v_country_rec.country_name||'thehighestelevationis:'||v_country_rec.highest_elevation||'andtheclimateis:'||v_country_rec.climate);
 
ENDLOOP;END;4. WriteaPL/SQLblocktofetchanddisplayallthecountriesthathavemorethansixspokenlanguages.Foreachsuchcountry,displaycountry_nameandthenumberofspokenlanguages.UseacursorFORloop,butdeclarethecursorexplicitlyintheDECLAREsection.Afteralltherowshavebeenfetchedanddisplayed,displayanextrarowshowingthetotalnumberofcountrieshavingmorethansixlanguages.(Hint:Declareavariabletoholdthevalueof%ROWCOUNT.)DECLARECURSORcountry_lang_cursorISSELECTc.country_name,count(*)FROMwf_countriesc,wf_spoken_languagessWHEREc.country_id=s.country_idGROUPBYc.country_nameHAVINGcount(*)>6ORDERBYc.country_name;lv_countNUMBER(2);lv_rowsNUMBER(2);country_lang_recordcountry_lang_cursor%ROWTYPE;BEGINFORcountry_lang_recordINcountry_lang_cursorLOOPSELECTcount(*)intolv_countFROMwf_countriesc,wf_spoken_languagessWHEREc.country_id=s.country_idANDc.country_name=country_lang_record.country_nameHAVINGcount(*)>6;DBMS_OUTPUT.PUT_LINE(country_lang_record.country_name||'has'||lv_count||'spokenlanguages.');lv_rows:=country_lang_cursor%ROWCOUNT;ENDLOOP;DBMS_OUTPUT.PUT_LINE(lv_rows||'countriesspeakmorethan6languages.');END;5. WriteaPL/SQLblocktodisplaythecountry_nameandareaofallcountriesinachosenregion.Theregion_idshouldbepassedtothecursorasaparameter.Testyourblockusingtworegion_ids:5(SouthAmerica)and30(EasternAsia).DonotuseacursorFORloop.DECLAREv_region_idwf_world_regions.region_id%TYPE:=:h_REGION_ID;CURSORcountry_cur(p_region_idNUMBER)ISSELECTcountry_name,areaFROMwf_countriesWHEREregion_id=p_region_id;v_country_reccountry_cur%ROWTYPE;BEGINOPENcountry_cur(v_region_id);LOOPFETCHcountry_curINTOv_country_rec;EXITWHENcountry_cur%NOTFOUND;DBMS_OUTPUT.PUT_LINE('Name:'||v_country_rec.country_name||'Area:'||v_country_rec.area);ENDLOOP;CLOSEcountry_cur;END;6. WriteaPL/SQLblockthatinsertsarowintoproposed_raisesforeachel

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->