0% found this document useful (0 votes)
11 views3 pages

cs405 assignment

ASSIGNMENT

Uploaded by

Mehersajid Sajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

cs405 assignment

ASSIGNMENT

Uploaded by

Mehersajid Sajid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Question # 01 (10pts) Write a PL/SQL program to count the number of employees in a specific

department and check whether this department have any vacancies or not. If any vacancies, how many
vacancies are in that department (Using If-Else Statement).

DECLARE

v_department_id NUMBER := 10; -- Replace with your specific department ID

v_employee_count NUMBER;

v_max_employees NUMBER;

v_vacancies NUMBER;

BEGIN

-- Count the number of employees in the specified department

SELECT COUNT(*)

INTO v_employee_count

FROM employees

WHERE department_id = v_department_id;

-- Get the maximum number of employees for the department

SELECT max_employees

INTO v_max_employees

FROM departments

WHERE department_id = v_department_id;

-- Calculate the number of vacancies

v_vacancies := v_max_employees - v_employee_count;

-- Check if there are vacancies and output results

IF v_vacancies > 0 THEN

DBMS_OUTPUT.PUT_LINE('Department ' || v_department_id || ' has ' || v_employee_count || '


employees.');

DBMS_OUTPUT.PUT_LINE('There are ' || v_vacancies || ' vacancies in this department.');


ELSE

DBMS_OUTPUT.PUT_LINE('Department ' || v_department_id || ' has ' || v_employee_count || '


employees.');

DBMS_OUTPUT.PUT_LINE('There are no vacancies in this department.');

END IF;

EXCEPTION

WHEN NO_DATA_FOUND THEN

DBMS_OUTPUT.PUT_LINE('Department ID ' || v_department_id || ' does not exist.');

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

Question # 02 (10pts) Write a PL/SQL program to display the job IDs, titles, and minimum salaries of all
jobs (Using While Loop). Sample output is mentioned below:

DECLARE

CURSOR job_cursor IS

SELECT job_id, job_title, min_salary FROM jobs;

v_job_id jobs.job_id%TYPE;

v_job_title jobs.job_title%TYPE;

v_min_salary jobs.min_salary%TYPE;

v_done BOOLEAN := FALSE; -- Variable to track loop completion

BEGIN

OPEN job_cursor;
LOOP

FETCH job_cursor INTO v_job_id, v_job_title, v_min_salary;

-- Check if the cursor has more rows to fetch

IF job_cursor%NOTFOUND THEN

v_done := TRUE; -- Set done to true when no more rows

ELSE

DBMS_OUTPUT.PUT_LINE('Job ID: ' || v_job_id ||

', Job Title: ' || v_job_title ||

', Minimum Salary: ' || v_min_salary);

END IF;

EXIT WHEN v_done; -- Exit loop when done

END LOOP;

CLOSE job_cursor;

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);

END;

You might also like