Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PL/SQL Cursor Exercises: Find out the start date for current job of a specific employee

PL/SQL Cursor: Exercise-40 with Solution

Write a PL/SQL block to find out the start date for current job of a specific employee.

Sample Solution:

PL/SQL Code:

DECLARE
    emp_st_date DATE;
    wr_emp_id   employees.employee_id%TYPE := &enter_employee_id;
BEGIN
    SELECT Max(end_date) + 1
    INTO   emp_st_date
    FROM   job_history
    WHERE  employee_id = wr_emp_id;

    IF emp_st_date IS NULL THEN
      SELECT hire_date
      INTO   emp_st_date
      FROM   employees
      WHERE  employee_id = wr_emp_id;
    END IF;

dbms_output.Put_line('----------------------------------------------------------------------');

dbms_output.Put_line('The starting date of current job for the employee  '
                     ||wr_emp_id
                     ||' is: '
                     ||emp_st_date);
END;
/

Sample Output:

SQL> /
Enter value for enter_employee_id: 189
old   3:     wr_emp_id   employees.employee_id%TYPE := &enter_employee_id;
new   3:     wr_emp_id   employees.employee_id%TYPE := 189;
----------------------------------------------------------------------
The starting date of current job for the employee  189 is: 13-AUG-05

PL/SQL procedure successfully completed.

Flowchart:

Flowchart: PL/SQL Cursor Exercises - Find out the start date for current job of a specific employee

Improve this sample solution and post your code through Disqus

Previous: Write a PL/SQL block to display the last name of manager, and their departments for a particular city, using parameters with a default value in explicit cursor.
Next: Write a PL/SQL block to display the last name, first name and overpaid amount by adding formal parameters and specify a default values for the added parameters

What is the difficulty level of this exercise?