Knowee
Questions
Features
Study Tools

QueryException_2Please go through the below Function and Exception spec:(a) Function: Create a function named 'find_staff_name_by_dept' thatl accepts the dept_id as input. Based on this input, the function must return the staff name. ie the function returns the names of staff belonging to this department.Hints:Function name : find_staff_name_by_dept, Input Parameter : dept_id in numberOutputs : 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 staff_name of the given dept_id.   2)If the deparment id(ie dept_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'. 3)If the deparment has more than one staff ,then it throws an exeption 'TOO_MANY_ROWS' and display it as 'Multiple Rows Returned' .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 procedure nameDo not change the argument count and orderDo not change the output text. Instructions:1. Create the procedure successfully2. Once the procedure is created, check the functionality of the procedure using different anonymous block call.3. DO NOT submit the anonymous block. Submit only the CREATE PROCEDURE query. SubmitSaveExecute

Question

QueryException_2Please go through the below Function and Exception spec:(a) Function: Create a function named 'find_staff_name_by_dept' thatl accepts the dept_id as input. Based on this input, the function must return the staff name. ie the function returns the names of staff belonging to this department.Hints:Function name : find_staff_name_by_dept, Input Parameter : dept_id in numberOutputs : 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 staff_name of the given dept_id.   2)If the deparment id(ie dept_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'. 3)If the deparment has more than one staff ,then it throws an exeption 'TOO_MANY_ROWS' and display it as 'Multiple Rows Returned' .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 procedure nameDo not change the argument count and orderDo not change the output text. Instructions:1. Create the procedure successfully2. Once the procedure is created, check the functionality of the procedure using different anonymous block call.3. DO NOT submit the anonymous block. Submit only the CREATE PROCEDURE query. SubmitSaveExecute

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

Solution

It seems like you're asking for help in creating a PL/SQL function that retrieves staff names based on a department ID. Here's a step-by-step guide on how to do it:

  1. First, we need to declare the function. We'll call it find_staff_name_by_dept and it will take one parameter, dept_id, which is a number.
CREATE OR REPLACE FUNCTION find_staff_name_by_dept(dept_id IN NUMBER) 
RETURN VARCHAR2 IS
  1. Next, we need to declare a variable to hold the staff name. We'll call it staff_name and it will be of type VARCHAR2.
staff_name VARCHAR2(100);
  1. Now we need to write the SQL query that will retrieve the staff name based on the department ID. We'll use a SELECT INTO statement for this.
BEGIN
  SELECT staff_name INTO staff_name FROM department WHERE department_id = dept_id;
  1. We need to handle exceptions. If no data is found, we'll raise a 'No Such Department' exception. If more than one row is returned, we'll raise a 'Multiple Rows Returned' exception.
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    staff_name := 'No Such Department';
    RETURN staff_name;
  WHEN TOO_MANY_ROWS THEN
    staff_name := 'Multiple Rows Returned';
    RETURN staff_name;
  1. Finally, we need to return the staff name and end the function.
  RETURN staff_name;
END find_staff_name_by_dept;

So, the complete function would look like this:

CREATE OR REPLACE FUNCTION find_staff_name_by_dept(dept_id IN NUMBER) 
RETURN VARCHAR2 IS
  staff_name VARCHAR2(100);
BEGIN
  SELECT staff_name INTO staff_name FROM department WHERE department_id = dept_id;
  RETURN staff_name;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    staff_name := 'No Such Department';
    RETURN staff_name;
  WHEN TOO_MANY_ROWS THEN
    staff_name := 'Multiple Rows Returned';
    RETURN staff_name;
END find_staff_name_by_dept;

Please replace department and `

This problem has been solved

Similar Questions

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​

Problem StatementWrite a query to display the details of employees who are not in the 'Developer' department. Table: EmployeeInput format :The input table is already created, and records are already prepopulated, as mentioned in the problem statement.Output format :The output displays a list of employees who work in departments other than 'Developer' as shown below.id name Department102 Stark HR104 Jack Finance106 Scott AdminRefer to the sample output for the column headers.Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Evaluate below sql statement SELECT emp_name, department FROM employees WHERE department = 'HR' UNION SELECT contractor_name, department FROM contractors WHERE department = 'IT';Select one:a. Retrieves the names of all employees and contractors from the HR and IT departments.b. Retrieves the names of employees from the HR department and all contractors.c. Retrieves the names of employees and contractors from the HR and IT departments, excluding employees from the IT department and contractors from the HR department.d. Retrieves the names of employees from the HR department and contractors from the IT department.

Review this SQL Statement: SELECT ename, emp_number, salary FROM employee WHERE dept_number = (SELECT dept_number FROM department WHERE location IN('CHICAGO','ATLANTA')); Why may this statement return an error?

Examine which part of the query will be executed first for the query given below.Select Employee_id,Employee_Name from Employeewhere Department_Name in(Select Department_Name from Employee where Department_name in (‘Sales’,'Marketing’));

1/2

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.