Knowee
Questions
Features
Study Tools

Create a package named "dept_package".Declare and define the following 4 Procedures in this package.1) Procedure to insert a new record in the department table.    Name : addDepartment    Parameters and their types :        dept_id   department.department_id%type        dept_name  department.department_name%type        dept_block_number  department.department_block_number%type 2) Procedure to delete a department when department id is passed as the input parameter.    Name : deleteDepartment    Parameters and their types :        dept_id   department.department_id%type        3) Procedure to list the details of all departments (id, name and block number) in ascending order based on id.     Name : listDepartment     Parameters and their types :        It uses cursors        dept_details OUT SYS_REFCURSOR        4) Procedure to update a department name (Given the old dept name and new dept name)      Name : updateDepartment      Parameters and their types :        dept_name  department.department_name%type        new_dept_name  department.department_name%type  Note:Do not change the package or procedure nameDo not change the argument count and orderDo not change the output text.Instructions:1. Create the package successfully2. Once the package is created, check the functionality of the procedure using different anonymous block call.3. DO NOT submit the anonymous block. Submit only the CREATE PACKAGE query. SubmitSaveExecutePrevious Submission

Question

Create a package named "dept_package".Declare and define the following 4 Procedures in this package.1) Procedure to insert a new record in the department table.    Name : addDepartment    Parameters and their types :        dept_id   department.department_id%type        dept_name  department.department_name%type        dept_block_number  department.department_block_number%type 2) Procedure to delete a department when department id is passed as the input parameter.    Name : deleteDepartment    Parameters and their types :        dept_id   department.department_id%type        3) Procedure to list the details of all departments (id, name and block number) in ascending order based on id.     Name : listDepartment     Parameters and their types :        It uses cursors        dept_details OUT SYS_REFCURSOR        4) Procedure to update a department name (Given the old dept name and new dept name)      Name : updateDepartment      Parameters and their types :        dept_name  department.department_name%type        new_dept_name  department.department_name%type  Note:Do not change the package or procedure nameDo not change the argument count and orderDo not change the output text.Instructions:1. Create the package successfully2. Once the package is created, check the functionality of the procedure using different anonymous block call.3. DO NOT submit the anonymous block. Submit only the CREATE PACKAGE query. SubmitSaveExecutePrevious Submission

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the SQL code to create the package "dept_package" with the specified procedures:

CREATE OR REPLACE PACKAGE dept_package AS
  PROCEDURE addDepartment(
    dept_id department.department_id%type,
    dept_name department.department_name%type,
    dept_block_number department.department_block_number%type
  );
  
  PROCEDURE deleteDepartment(
    dept_id department.department_id%type
  );
  
  PROCEDURE listDepartment(
    dept_details OUT SYS_REFCURSOR
  );
  
  PROCEDURE updateDepartment(
    dept_name department.department_name%type,
    new_dept_name department.department_name%type
  );
END dept_package;
/

CREATE OR REPLACE PACKAGE BODY dept_package AS
  PROCEDURE addDepartment(
    dept_id department.department_id%type,
    dept_name department.department_name%type,
    dept_block_number department.department_block_number%type
  ) IS
  BEGIN
    INSERT INTO department(department_id, department_name, department_block_number)
    VALUES (dept_id, dept_name, dept_block_number);
  END addDepartment;
  
  PROCEDURE deleteDepartment(
    dept_id department.department_id%type
  ) IS
  BEGIN
    DELETE FROM department WHERE department_id = dept_id;
  END deleteDepartment;
  
  PROCEDURE listDepartment(
    dept_details OUT SYS_REFCURSOR
  ) IS
  BEGIN
    OPEN dept_details FOR
    SELECT department_id, department_name, department_block_number
    FROM department
    ORDER BY department_id ASC;
  END listDepartment;
  
  PROCEDURE updateDepartment(
    dept_name department.department_name%type,
    new_dept_name department.department_name%type
  ) IS
  BEGIN
    UPDATE department
    SET department_name = new_dept_name
    WHERE department_name = dept_name;
  END updateDepartment;
END dept_package;
/

This code first creates the package specification, which declares the procedures that will be included in the package. Then, it creates the package body, which provides the definitions for these procedures. The procedures perform the operations of adding a new department, deleting a department, listing all departments, and updating a department name, as specified.

This problem has been solved

Similar Questions

Problem StatementIn a company's Employee Management System, a database table named "Employees" that stores information about employees, including their EmployeeID, EmployeeName, Department, and Salary.The HR department needs a mechanism to delete employee records from the system when an employee leaves the company or for any other valid reason. To address this requirement, you are tasked with creating a stored procedure named "DeleteEmployee," which takes an EmployeeID as input and deletes the corresponding employee record from the "Employees" table.The following table is already created, and the records are inserted into the table.TABLE: Employees EmployeeID INT PRIMARY KEY, EmployeeName VARCHAR(50), Department VARCHAR(50), Salary DECIMAL(10, 2)Prepopulated Records:Input format :The input records are already prepopulated, as given in the problem statement.Output format :The stored procedure deletes the employee record based on the provided EmployeeID.The output should display the employee details after deletion as shown below.EmployeeID EmployeeName Department Salary1 John Doe IT 60000.002 Jane Smith HR 55000.003 Bob Johnson Marketing 70000.004 Alice Williams Finance 80000.00EmployeeID EmployeeName Department Salary1 John Doe IT 60000.003 Bob Johnson Marketing 70000.004 Alice Williams Finance 80000.00Refer to the sample output for the column headers.

Write a query to update the departmentId as "A10" for the details "InformationTechnology" and "E10" for the details "ElectricalElectronicsEngineering" print only the departmentId and details from the department table.

Write a query to modify the datatype of the column departmentId from VARCHAR(30) to INT in the table 'department'.Refer to the existing table DLL given below:

Please go through the below Function and Exception spec:(a) Function: A Function must be created that will accept the dept_id as input. Based on this input, the function must return the department name. Function name : find_dept_name, Input Parameter : dept_id in intOutput Parameter : A VARIABLE WITH varchar TYPE Design rules:1)If department id(ie dept_id) passed as input, matches with the department_id in the department table,then it returns the department_name of the given dept_id.   2)If the deparment id passed as input, does not match with the department_id in the department table,then it throws 'no_data_found' exception and display it as  'No such department'Note: Kindly use variable to print the exceptions instead of  'dbms_output.put_line'ie:   umpire_name  := 'No such umpire';Note:Do not change the function nameDo not change the argument count and orderDo not change the output text. Instructions:1. Create the function successfully2. Once the function is created, check the functionality of the function.3. Submit only the CREATE FUNCTION query. SubmitSaveExecutePrevious Submission1​

Consider the school database, where the primary keys are underlined:student (student_id, name, address,gender)course (u, course_name, year)department (dept_number, date, department_name)                                 i.             Write an SQL statement to add a new record into the department table. (3 Marks)                           ii.            Write an SQL statement to delete all the records from the course table. (2 Marks)Answer text Question 4EditViewInsertFormatToolsTableHelp

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.