0% found this document useful (0 votes)
6 views2 pages

TPCURSEURPARAM

The document contains PL/SQL code that defines a cursor to retrieve employee data based on service numbers, calculating total employees, average salary, and total salary for specified services. It also includes a loop to update salaries by 10% for employees in service number 10. The results are outputted using DBMS_OUTPUT statements to indicate the status of the data retrieval and updates.

Uploaded by

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

TPCURSEURPARAM

The document contains PL/SQL code that defines a cursor to retrieve employee data based on service numbers, calculating total employees, average salary, and total salary for specified services. It also includes a loop to update salaries by 10% for employees in service number 10. The results are outputted using DBMS_OUTPUT statements to indicate the status of the data retrieval and updates.

Uploaded by

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

TP//Curseur parametré

DECLARE
CURSOR emp_cursor (numserv IN NUMBER) IS
SELECT COUNT(*) AS total__emp, AVG(SalaireP) AS avg_sal, SUM(SalaireP) AS tot_sal
FROM Personne
WHERE NumServP=numserv
GROUP BY NumServP;

total_people NUMBER;
avg_salary NUMBER;
total_salary NUMBER;

BEGIN
OPEN emp_cursor(10);
FETCH emp_cursor INTO total_people, avg_salary, total_salary;
IF emp_cursor%FOUND THEN
DBMS_OUTPUT.PUT_LINE('Service 10 - Total number of people: ' || total_people);
ELSE
DBMS_OUTPUT.PUT_LINE('Service 10 - No data found.');
END IF;
CLOSE emp_cursor;

OPEN emp_cursor(30);
FETCH emp_cursor INTO total_people, avg_salary, total_salary;
IF emp_cursor%FOUND THEN
DBMS_OUTPUT.PUT_LINE('Service 30 - Average salary: ' || avg_salary);
ELSE
DBMS_OUTPUT.PUT_LINE('Service 30 - No data found.');
END IF;
CLOSE emp_cursor;

OPEN emp_cursor(60);
FETCH emp_cursor INTO total_people, avg_salary, total_salary;
IF emp_cursor%FOUND THEN
DBMS_OUTPUT.PUT_LINE('Service 60 - Total salary: ' || total_salary);
ELSE
DBMS_OUTPUT.PUT_LINE('Service 60 - No data found.');
END IF;
CLOSE emp_cursor;
END;
/
DECLARE
CURSOR emp_cursor IS
SELECT SalaireP
FROM Personne
WHERE NumServP = 10
FOR UPDATE;

salaire Personne.SalaireP%TYPE;

BEGIN
OPEN emp_cursor;

LOOP
FETCH emp_cursor INTO salaire;
EXIT WHEN emp_cursor%NOTFOUND;

UPDATE Personne
SET SalaireP = SalaireP * 1.10
WHERE CURRENT OF emp_cursor;

END LOOP;

DBMS_OUTPUT.PUT_LINE('Salaires du service 10 augmentés de 10%.');

CLOSE emp_cursor;

END;
/

You might also like