Ubd Lab7
Ubd Lab7
7
Observație!
Scrieți rezolvarea direct în acest document!
Creating Procedures
1. Create, save and execute a procedure which updates the salary of employees in employees_dup
according to the following rules:
You will need to include three UPDATE statements, one for each of the above rules. Execute your
procedure from an anonymous block and verify that the updates have been performed correctly.
A. Create a procedure that accepts a country_id as a parameter and displays the name of the country
and its capitol city. Name your procedure get_country_info. Save your procedure definition for later
use.
BEGIN
get_country_info(90);
END;
The country name is Republic of Turkey and the capital city is Ankara.
C. Re-execute the procedure from the anonymous block, this time using country_id 95. What
happens?
D. Retrieve your procedure code from Saved SQL and modify it to trap the NO_DATA_FOUND
exception in an exception handler. Re-execute the procedure using country_id 95 again. Now what
happens?
Passing Parameters
1. Create and test a procedure which accepts a department id as an IN parameter with a default
value of 50, and returns (using OUT parameters) the last name and salary of the employee in that
department who has the highest salary. The SELECT statement in the procedure should use a
subquery. Test your procedure twice from an anonymous block, the first time using department
id 80, the second time using the default value.
/*department_id=80*/
DECLARE
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
highest_sal(80, v_last_name, v_salary);
DBMS_OUTPUT.PUT_LINE('Last name: ' || v_last_name || ' earns: ' || v_salary);
END;
/*default value*/
DECLARE
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
highest_sal(p_last_name => v_last_name, p_salary => v_salary);
DBMS_OUTPUT.PUT_LINE('Last name: ' || v_last_name || ' earns: ' || v_salary);
END;