﻿ PL/SQL Cursor: Display the number of employees by month. Print number of employees by month - w3resource

# PL/SQL Cursor Exercises: Display the number of employees by month. Print number of employees by month

## PL/SQL Cursor: Exercise-38 with Solution

Write a PL/SQL block to display the number of employees by month. Print number of employees by month.

Sample Solution:

PL/SQL Code:

``````DECLARE
st_month NUMBER(2) := 1;
no_o_emp NUMBER(3);
BEGIN
|| 'Number of Employees');
dbms_output.Put_line('-------------------------------------------------------------');

FOR month IN 1 .. 12 LOOP
SELECT Count(*)
INTO   no_o_emp
FROM   employees
WHERE  To_char(hire_date, 'mm') = month;

|| To_char(no_o_emp, '999'));
END LOOP;
END;
/
``````

Sample Output:

```SQL> /
Month No            Month Name          Number of Employees
-----------------------------------------------------------
01                 JANUARY               14
02                 FEBRUARY              13
03                 MARCH                 17
04                 APRIL                  7
05                 MAY                    6
06                 JUNE                  11
07                 JULY                   7
08                 AUGUST                 9
09                 SEPTEMBER              5
10                 OCTOBER                6
11                 NOVEMBER               5
12                 DECEMBER               7

PL/SQL procedure successfully completed.

```

Flowchart:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

﻿

Inviting useful, relevant, well-written and unique guest posts