Advertisement
Alex9090

Untitled

Jan 17th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. EX1
  2. ---------------------------------------------------------------------
  3.  
  4. CREATE OR replace FUNCTION f2 (v_id employees.department_id%type )
  5. RETURN varchar2 IS nume employees.last_name%type;nume2 employees.last_name%type;
  6. BEGIN
  7. SELECT last_name
  8. INTO nume
  9. FROM employees
  10. WHERE v_id=employees.department_id
  11. AND salary =
  12. (
  13. SELECT max(salary)
  14. FROM employees);
  15.  
  16. for k IN
  17. (
  18. SELECT last_name nume2
  19. FROM employees
  20. WHERE v_id = department_id)
  21. loop dbms_output.put_line('Angajat din dep :' || k.nume2);
  22. end loop;
  23. return nume;
  24. exception
  25. WHEN no_data_found THEN
  26. raise_application_error(-20000, 'Nu exista angajati cu numele dat');
  27. when too_many_rows THEN
  28. raise_application_error(-20001, 'Exista mai multi angajati cu numele dat');
  29. when others THEN
  30. raise_application_error(-20002,'Alta eroare!');
  31. end f2;
  32. BEGIN
  33. dbms_output.put_line('Salariul este '|| f2(90));END;
  34.  
  35. EX2
  36. -------------------------------------------------------------
  37.  
  38. CREATE OR replace PROCEDURE f3 (v_nume employees.last_name%type, v_nume1 employees.first_name%type ) IS nume employees.last_name%type;
  39. var1 varchar2(35) :='IT Support';var2 varchar2(35) :='Benefits';v3 varchar(35);BEGIN
  40. SELECT department_name
  41. INTO v3
  42. FROM departments,
  43. employees
  44. WHERE v_nume = employees.last_name
  45. AND departments.department_id = employees.department_id
  46. AND v_nume1=employees.first_name;
  47.  
  48. IF var1 = v3 then
  49. dbms_output.put_line('IT Support');
  50. elsif var2 = v3 THEN
  51. dbms_output.put_line('Benefits');
  52. else dbms_output.put_line('NU');
  53. endif;
  54. exception
  55. WHEN no_data_found THEN
  56. raise_application_error(-20000, 'Nu exista angajati cu numele dat');
  57. when too_many_rows THEN
  58. raise_application_error(-20001, 'Exista mai multi angajati cu numele dat');
  59. when others THEN
  60. raise_application_error(-20002,'Alta eroare!');
  61. ENDf3;/
  62. BEGIN
  63. f3('King', 'Steven');END;/
  64.  
  65. EX 3
  66. ---------------------------------------------------------------------------
  67.  
  68. CREATE OR replace TRIGGER trig21 beforeupdate OF salary ON employees FOR each rowdeclare sal_max employees.salary%type;BEGIN
  69. SELECT Max(salary)
  70. INTO sal_max
  71. FROM employees;
  72. IF (:new.salary > sal_max) then
  73. raise_application_error(-20007,'salariul nu poate fi marit');
  74. endif;
  75. END;/UPDATE employees
  76. SET salary = 25000;DROP TRIGGER trig21;/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement