You are on page 1of 3

PL/SQL LAB Session 1

I. Identify valid and invalid identifiers


a. today
b. last_name
c. today’s_date
d. Nb_of_days_in_february_this_year
e. #number
f. Number#
g. Isleap$year
h. Number1to100

II. Identify valid variable declarations and initializations

a. v_nb_copies PLS_INTEGER;
b. printer_name CONSTANT VARCHAR2(15);
c. deliver_to VARCHAR2(15) := ASTEC corporation;
d. by_when DATE := CURRENT_DATE +1 (ORACLE built-in functions)

III. Variables scope and visibility

BEGIN <<OUTER>>
DECLARE
v_sal NUMBER(7,2) := 60000;
v_comm NUMBER(7,2) := v_sal * 0.20;
v_message VARCHAR2(255) := ' eligible for commission';
BEGIN
DECLARE
v_sal NUMBER(7,2) := 50000;
v_comm NUMBER(7,2) := 0;
v_total_comp NUMBER(7,2) := v_sal + v_comm;
BEGIN
v_message := 'CLERK not' || v_message; ------------ Position 1
outer.v_comm := v_sal * 0.30;
END;
v_message := 'SALESMAN'||v_message; ------------ Position 2
END;
END outer;

Determine each of the following values according to the rules of scoping:


1. Value of v_message at position 1
2. Value of v_total_comp at position 2
3. Value of v_comm at position 1
4. Value of outer.v_comm at position 1
5. Value of v_comm at position 2
6. Value of v_message at position 2

IV. Create an anonymous bloc that:


1. Reads first name and salary of the employee 120
2. Prints Hello with the first name
3. Calculates the contribution of the employee which is 12% of the basic salary, the
basic salary being 60% of the salary.
4. Prints the salary of the employee and his contribution.

V. Write a program to interchange the salaries of employee 120 and 122 and print for each of
them his first name, last name and new salary.

VI. SQL Review, some of the following SQL queries will be done in the lab session

HR Table Descriptions

COUNTRIES (country_id, country_name, region_id)


DEPARTMENTS (department_id, department_name, manager_id, location_id)
EMPLOYEES (employee_id, first_name, last_name, email, phone_number,
hire_date, job_id, salary, commission_pct, manager_id,
department_id)
JOB (job_id, title, min_salary, max_salary)
JOB_HISTORY (employee_id, start_date, end_date, job_id, department_id)
LOCATIONS (location_id, street_address, postal_code, city, state_province,
country_id)
REGIONS (region_id, region_name)

1. Display details of jobs that were done by any employee who is currently drawing more
than 15000 of salary.
2. Display department name, manager name, and salary of the manager for all managers
whose experience is more than 5 years.
3. Display employee name if the employee joined before his manager.
4. Display employee name, job title for the jobs employee did in the past where the job was
done less than 12 months.
5. Display employee name and country in which he is working.
6. Display department name, average salary and number of employees with commission
within the department.
7. Display the month in which more than 5 employees joined in any department located in
city Seattle.
8. Display details of departments in which the maximum salary is more than 10000.
9. Display details of departments managed by ‘Steven’.
10. Display jobs into which employees joined in the current year.
11. Display employees who did not do any job in the past.
12. Display job title and average salary for employees who did a job in the past.
13. Display country name, city, and number of departments where department has more than
5 employees.
14. Display details of manager who manages more than 5 employees.
15. Display employee name, job title, start date, and end date of past jobs of all employees
with commission percentage null.
16. Display the departments into which no employee joined in last two years.
17. Display the details of departments in which the max salary is greater than 10000 for
employees who did a job in the past.
18. Display details of current job for employees who worked as IT Programmers in the past.
19. Display the details of employees drawing the highest salary in the department.
20. Display the city of employee whose employee ID is 105.
21. Display third highest salary of all employees.
22. Display employee name if the employee joined before his manager.

You might also like