Created
November 9, 2023 06:25
-
-
Save ciurca/2710acf6756e27d162dec9185c8ca795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Exercitiul 1 (Salariul Mediu) | |
DECLARE | |
v_functie angajati.job_id%TYPE:='SA_REP'; | |
v_salariu_mediu angajati.salary%TYPE; | |
BEGIN | |
SELECT AVG(salary) INTO v_salariu_mediu FROM ANGAJATI WHERE job_id=v_functie; | |
dbms_output.put_line(v_salariu_mediu); | |
END; |
Author
ciurca
commented
Nov 12, 2023
-- Exercitiul 8 (vechime)
DECLARE
CURSOR c_reprezentanti (id_job VARCHAR2, p_vechime NUMBER) IS
SELECT first_name, last_name, salary FROM angajati
WHERE job_id=id_job AND extract(year from hire_date) <= extract(year from SYSDATE) - p_vechime;
v_first_name angajati.first_name%TYPE;
v_last_name angajati.last_name%TYPE;
v_salary angajati.salary%TYPE;
v_salariu_mediu angajati.salary%TYPE;
BEGIN
OPEN c_reprezentanti('SA_REP', 7);
LOOP
FETCH c_reprezentanti INTO v_first_name, v_last_name, V_salary;
EXIT WHEN c_reprezentanti%notfound;
DBMS_OUTPUT.PUT_LINE(v_first_name || ' ' || v_last_name || ' ' || v_salary);
END LOOP;
CLOSE c_reprezentanti;
SELECT AVG(salary) INTO v_salariu_mediu FROM ANGAJATI WHERE job_id='SA_REP';
DBMS_OUTPUT.PUT_LINE('Salariu mediu: ' || v_salariu_mediu);
END;
-- Exercitiul 9 (functii)
DECLARE
CURSOR c_reprezentanti (id_job VARCHAR2) IS
SELECT first_name, last_name, salary FROM angajati
WHERE job_id=id_job
ORDER BY first_name, last_name;
v_first_name angajati.first_name%TYPE;
v_last_name angajati.last_name%TYPE;
v_salary angajati.salary%TYPE;
v_salariu_mediu angajati.salary%TYPE;
v_fond_lunar angajati.salary%TYPE:=0;
PROCEDURE functii_dept(id_dept IN VARCHAR2) IS
BEGIN
OPEN c_reprezentanti(id_dept);
LOOP
FETCH c_reprezentanti INTO v_first_name, v_last_name, V_salary;
EXIT WHEN c_reprezentanti%notfound;
DBMS_OUTPUT.PUT_LINE(v_first_name || ' ' || v_last_name || ' ' || v_salary);
v_fond_lunar:=v_fond_lunar+v_salary;
END LOOP;
CLOSE c_reprezentanti;
SELECT AVG(salary) INTO v_salariu_mediu FROM ANGAJATI WHERE job_id=id_dept;
DBMS_OUTPUT.PUT_LINE('-------------');
DBMS_OUTPUT.PUT_LINE('Salariu mediu pentru ' || id_dept || ': ' || v_salariu_mediu);
DBMS_OUTPUT.PUT_LINE('Fond salarial pentru ' || id_dept || ': ' || v_fond_lunar);
v_fond_lunar:=0;
DBMS_OUTPUT.PUT_LINE('');
END;
BEGIN
functii_dept('SA_REP');
functii_dept('ST_CLERK');
END;
-- Exercitiul 10 (scadere salariala)
DECLARE
CURSOR c_reprezentanti IS
SELECT employee_id, salary FROM angajati
WHERE job_id='SA_REP' OR job_id='SA_MAN'
FOR UPDATE WAIT 5;
r_reprezentanti c_reprezentanti%ROWTYPE;
BEGIN
OPEN c_reprezentanti;
LOOP
FETCH c_reprezentanti INTO r_reprezentanti;
EXIT WHEN c_reprezentanti%notfound;
UPDATE angajati
SET salary = r_reprezentanti.salary - (r_reprezentanti.salary*5/100)
WHERE employee_id = r_reprezentanti.employee_id;
END LOOP;
COMMIT;
dbms_output.put_line('Nr. de personal a caror salarii au fost scazute cu 5%: ' || c_reprezentanti%ROWCOUNT);
CLOSE c_reprezentanti;
END;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment