Advertisement
Guest User

Untitled

a guest
May 24th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. set serveroutput on
  2. create or replace procedure proc1
  3. (p_id in number)
  4. is
  5. cursor c
  6. is
  7. select c.nr_comanda, c.data
  8. from rand_comenzi rc, comenzi c
  9. where rc.id_produs=p_id
  10. and rc.nr_comanda = c.nr_comanda
  11. order by c.data desc;
  12. begin
  13. for i in c loop
  14. dbms_output.put_line(i.nr_comanda||' '|| i.data);
  15. exit when c%ROWCOUNT > 4;
  16. end loop;
  17. end;
  18. /
  19.  
  20. begin
  21. proc1(3129);
  22. end;
  23. /
  24.  
  25. set serveroutput on
  26. create or replace trigger triger1
  27. before insert or update of pret on rand_comenzi
  28. for each row
  29. declare
  30. p_id rand_comenzi.id_produs%type;
  31. p_min produse.pret_min%type;
  32. p_max produse.pret_lista%type;
  33. begin
  34. select p.id_produs, p.pret_min, p.pret_lista into p_id, p_min, p_max
  35. from produse p
  36. where p.id_produs=:new.id_produs;
  37. if inserting or updating
  38. and :new.pret < p_min
  39. or :new.pret > p_max
  40. then
  41. raise_application_error(-20202, 'Wrong price');
  42. end if;
  43. end;
  44. /
  45.  
  46. insert into rand_comenzi values(56,3255,37,30);
  47. update rand_comenzi set pret = 37 where nr_comanda = 2392;
  48.  
  49.  
  50.  
  51.  
  52.  
  53. set serveroutput on
  54. create or replace function function1(order_id rand_comenzi.nr_comanda%type)
  55. return number is p_number number;
  56. begin
  57. select sum(rc.pret*rc.cantitate) total into p_number
  58. from rand_comenzi rc
  59. where nr_comanda = order_id;
  60. return p_number;
  61. end;
  62. /
  63.  
  64. set serveroutput on
  65. declare
  66. p_nr number(5);
  67. begin
  68. p_nr := function1(2380);
  69. dbms_output.put_line('Total: '||p_nr);
  70. end;
  71. /
  72.  
  73.  
  74. set serveroutput on
  75. create or replace trigger trigger2
  76. BEFORE insert on comenzi
  77. for each row
  78. declare
  79. v_data angajati.data_angajare%type;
  80. v_nr number;
  81. v_job angajati.id_functie%type;
  82. begin
  83. select id_functie into v_job
  84. from angajati
  85. where id_angajat = :new.id_angajat;
  86. select data_angajare into v_data
  87. from angajati
  88. where id_angajat = :new.id_angajat;
  89. select (sysdate - v_data) into v_nr
  90. from angajati
  91. where id_angajat = :new.id_angajat;
  92. if inserting and v_job <> 'SA_REP' or v_nr<30 then
  93. raise_application_error(-20202, 'NU');
  94. end if;
  95. end;
  96. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement