0% found this document useful (0 votes)
172 views

CS405 Assignment 2 Solution Spring 2024

Assignment database

Uploaded by

Junaid Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views

CS405 Assignment 2 Solution Spring 2024

Assignment database

Uploaded by

Junaid Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CS405 ASSIGNMENT 2 SOLUTION SPRING 2024

Due Date: 21-June-2024


Total Marks: 20

DO NOT COPY PASTE SAME OTHERWISE MARKS AWARDED ZERO

FOR MORE CORRECT SOLUTIONS WITH YOUR OWN STUDENTS ID CONTACT


WHATSAPP +923162965677

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

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
Note: You are required to write the code and show its output and attach it with
your assignment file.

Solution:

CREATE TABLE employees


(
employee_id INT PRIMARY KEY,
e_fname VARCHAR(20),
e_lname VARCHAR(20),
email VARCHAR(40),
phone_number VARCHAR(15),
hire_date DATE,
job_id VARCHAR(10),
salary INT,
commission DECIMAL(10,1),
manager_id INT,
department_id INT
);

INSERT INTO employees (employee_id, e_fname, e_lname, email, phone_number, hire_date,


job_id, salary, commission, manager_id, department_id)
VALUES (1, 'Muhammad', 'Sarim', '[email protected]', '03162965677', TO_DATE('2016-06-
01', 'YYYY-MM-DD'), 'HR-101', 60000, 1000, 101, 60);

INSERT INTO employees (employee_id, e_fname, e_lname, email, phone_number, hire_date,


job_id, salary, commission, manager_id, department_id)

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
VALUES (2, 'Ali', 'Khan', '[email protected]', '0312236321', TO_DATE('2020-03-20', 'YYYY-
MM-DD'), 'IT-104', 45000, NULL, 104, 10);

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;

DBMS_OUTPUT.PUT_LINE(v_year || ' | ' || v_hire_count);

v_year := v_year + 1;
END LOOP;
END;
END;

OUTPUT:

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
Question # 2 (10pts)

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);

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
BEGIN
v_day_of_week := TO_CHAR(v_date, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH');

IF v_day_of_week = 'SAT' OR v_day_of_week = 'SUN' THEN


DBMS_OUTPUT.PUT_LINE('The date ' || TO_CHAR(v_date, 'YYYY-MM-DD') || '
falls on weekend.');
ELSE
DBMS_OUTPUT.PUT_LINE('The date ' || TO_CHAR(v_date, 'YYYY-MM-DD') || '
does not fall on weekend.');
END IF;
END;
END;

OUTPUT:

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
REGARD - SARIM
WHATSAPP +923162965677

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.

FOR FREE ASSIGNMENTS SOLUTIONS VISIT

VUStudentspk.com

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1

You might also like