CS405 Assignment 2 Solution Spring 2024
CS405 Assignment 2 Solution Spring 2024
Question # 01
(10
pts)
Write a PL/SQL program to display the total number of employees hired each
year between 2015 and 2024 by using WHILE loop and return the results in
tabular format. Sample employee table is mentioned below:
employee_id integer
e_fname varchar
e_lname varchar
email char
phone_number varchar
hire_date date
job_id varchar
salary integer
commission decimal
manaer_id integer
department_id integer
Solution:
BEGIN
DBMS_OUTPUT.PUT_LINE('Year | Number of Employees Hired');
DBMS_OUTPUT.PUT_LINE('-----------------------------');
DECLARE
v_year INTEGER := 2015;
v_hire_count INTEGER;
BEGIN
WHILE v_year <= 2024 LOOP
SELECT COUNT(*)
INTO v_hire_count
FROM employees
WHERE EXTRACT(YEAR FROM hire_date) = v_year;
v_year := v_year + 1;
END LOOP;
END;
END;
OUTPUT:
Write a PL/SQL program to check whether a date falls on weekend i.e. SATURDAY or
SUNDAY.
Note: You are required to write the code and show its output and attach it with
your assignment file.
Solution:
BEGIN
DECLARE
v_date DATE := TO_DATE('2024-06-15', 'YYYY-MM-DD');
v_day_of_week VARCHAR2(10);
OUTPUT:
PLEASE NOTE:
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before
submitting copy paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment must check your assignment requirement
file.
If you need some help or question about file and solutions feel free to ask.
VUStudentspk.com