Chapter 4 Practice: Employee Hutton Has An Annual Income of 158400 PL/SQL Procedure Successfully Completed. Com - PCT
Chapter 4 Practice: Employee Hutton Has An Annual Income of 158400 PL/SQL Procedure Successfully Completed. Com - PCT
1) Write the code that will prompt you for the employee’s Id and then will calculate the Annual
Income based on the value of “commission_pct” column. If that value does exist it should be
doubled (like some kind of reward for Good Sales year). Both numbers should be displayed.
Provide two examples where first employee is receiving the commission, while the other one is
not. Here is the output.
COM_PCT
.5
COM_PCT
0
2) You will write PL/SQL code that will insert a NEW employee with the following data:
First_name: Tim
Last_name: Ho
Email: It will be in the form of ‘whatever is the User’s name’ with the domain ‘yahoo.ca’
Job_d: FI_ACCOUNT
Department_id: You will be prompted for this Id and provide one of the existing values
Then you will verify the look of this new row (just for the columns that are not blank)
and then you will undo your insert. Here is the output.
Rollback complete.
3) You need to modify departments with NO manager so that one of the VP’s becomes their
manager. Criteria is also that chosen VP had to be hired in the eighties.
Display firstly last name of that manager and then # of departments that have been modified.
And finally undo you change. Here is the output.
Name of VP is Kochhar
# of departments that got Kochhar as a manager is 16
PL/SQL procedure successfully completed.
Rollback complete.
ANSWERS
1)
SET SERVEROUTPUT ON
SET VERIFY OFF
VARIABLE com_pct NUMBER
DECLARE
lname employees.last_name%TYPE;
income employees.salary%TYPE;
empno employees.employee_id%TYPE := &empid;
BEGIN
SELECT commission_pct INTO :com_pct
FROM employees
WHERE employee_id = empno;
IF :com_pct IS NOT NULL THEN
:com_pct := :com_pct*2;
ELSE
:com_pct := 0;
END IF;
SELECT last_name, salary*12*(1+ :com_pct)
INTO lname, income
FROM employees
WHERE employee_id = empno;
DBMS_OUTPUT.PUT_LINE('Employee ' || lname || ' has an annual income of ' ||
TO_CHAR(income));
END;
/
PRINT com_pct
2)
DECLARE
mail_name VARCHAR2(40);
h_date employees.hire_date%TYPE;
avg_sal employees.salary%TYPE;
v_dept employees.department_id%TYPE := &deptid;
v_emp employees.employee_id%TYPE;
BEGIN
SELECT USER INTO mail_name
FROM DUAL;
UPDATE departments
SET manager_id = empid
WHERE manager_id IS NULL;
DBMS_OUTPUT.PUT_LINE('# of departments that got ' || lname || ' as a manager is ' || SQL
%ROWCOUNT) ;
END;
/
ROLLBACK