Use of multiple cursors and parameters to create reports.
DECLARE CURSOR c_region IS SELECT * FROM wf_world_regions WHERE region_name LIKE '%America%' ORDER BY region_name; CURSOR c_country (p_regionId NUMBER) IS SELECT * FROM wf_countries WHERE region_id = p_regionId ORDER BY country_name; CURSOR c_language (p_countryID NUMBER) IS Select l.language_id, language_name, country_id FROM wf_spoken_languages sl, wf_languages l WHERE sl.language_id = l.language_id AND country_id = p_countryID ORDER BY language_name; BEGIN FOR v_regionRec IN c_region LOOP DBMS_OUTPUT.PUT_LINE(v_regionRec.region_id ||' '|| v_regionRec.region_name); DBMS_OUTPUT.PUT_LINE('----------'); FOR v_countryRec IN c_country (v_regionRec.region_id) LOOP DBMS_OUTPUT.PUT_LINE(v_countryRec.country_name||' '||v_countryRec.area||' '|| v_countryRec.population); FOR v_languageRec IN c_language (v_countryRec.country_id) LOOP DBMS_OUTPUT.PUT_LINE('-----'||v_languageRec.language_name); END LOOP; END LOOP; DBMS_OUTPUT.PUT_LINE(' '); END LOOP; END;
II.
Handling User Defined Exceptions.
DECLARE v_dept_id excep_emps.department_id%TYPE; v_count NUMBER; BEGIN v_dept_id := 40; SELECT COUNT(*) INTO v_count FROM excep_emps WHERE department_id = v_dept_id; IF v_count = 0 THEN RAISE_APPLICATION_ERROR(-20203,'There are no employees in this department'); END IF; DBMS_OUTPUT.PUT_LINE('There are ' || v_count || ' employees'); DELETE FROM excep_emps WHERE department_id = v_dept_id; IF SQL%ROWCOUNT = 0 THEN RAISE_APPLICATION_ERROR(-20204, 'No employees were deleted'); END IF; DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT || ' employees were deleted'); ROLLBACK; END;
III.
Creating Functions.
IV.
Creating Packages with Overloaded Procedures.
V.
Creating Triggers to maintain data integrity where check constraints would be ineffective.