Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. -----------------------------3----------------------------
  2. set serveroutput on;
  3. DECLARE
  4. TYPE rec_grad IS RECORD(grade salgrade.grade%type, hisal SALGRADE.HISAL%type, losal SALGRADE.loSAL%type);
  5. TYPE rc_grad IS REF CURSOR RETURN rec_grad;
  6. TYPE rec_nume IS RECORD(ename emp.ename%TYPE);
  7. TYPE rc_nume IS REF CURSOR RETURN rec_nume;
  8. cv_grad rc_grad;
  9. cv_nume rc_nume;
  10.  
  11. v_ename emp.ename%type;
  12. v_grade salgrade.grade%type;
  13. v_losal SALGRADE.loSAL%type;
  14. v_hisal salgrade.hisal%type;
  15. BEGIN
  16. OPEN cv_grad FOR
  17. SELECT grade, hisal, losal
  18. FROM SALGRADE
  19. WHERE grade = 2;
  20. LOOP
  21. FETCH cv_grad into v_grade, v_hisal, v_losal;
  22. EXIT WHEN cv_grad%notfound;
  23.  
  24. OPEN cv_nume FOR
  25. SELECT ename
  26. FROM emp
  27. WHERE sal < v_hisal AND sal>v_losal;
  28. LOOP
  29. FETCH cv_nume into v_ename;
  30. EXIT WHEN cv_nume%notfound;
  31.  
  32. dbms_output.put_line('Nume : '||v_ename||' grad: '||v_grade||' sal max: '||v_hisal);
  33. END LOOP;
  34. close cv_nume;
  35.  
  36. END LOOP;
  37. CLOSE cv_grad;
  38. end;
  39. /
  40.  
  41.  
  42. -------------------------------------2---------------------------------------
  43. CREATE OR REPLACE PACKAGE test_trigger IS
  44. procedure p2 (proc_ordid TRANSFER.ORDID%type, v_shipdate TRANSFER.SHIPDATE%type);
  45. END test_trigger;
  46. /
  47.  
  48. CREATE OR REPLACE PACKAGE BODY test_trigger IS
  49. procedure p2(proc_ordid TRANSFER.ORDID%type, v_shipdate TRANSFER.SHIPDATE%type)
  50. IS
  51. v2_shipdate TRANSFER.SHIPDATE%type;
  52. v_ordid TRANSFER.ORDID%type;
  53. --v_itemOrdid item.ordid%type;
  54. v_actualprice ITEM.ACTUALPRICE%type;
  55. v_itemtot ITEM.ITEMTOT%type;
  56. v_total ORD.TOTAL%type;
  57. --v_ordOrdid ORD.ORDID%type;
  58. v_itemid ITEM.ITEMID%type;
  59. exceptie exception;
  60. BEGIN
  61. SELECT ordid, shipdate into v_ordid, v2_shipdate from transfer where ordid=proc_ordid;
  62. SELECT itemid, actualprice, itemtot into v_itemid, v_actualprice, v_itemtot from item where ordid=proc_ordid;
  63. SELECT total into v_total from ord where ordid=proc_ordid;
  64.  
  65. dbms_output.put_line('Ord id'||proc_ordid|| ', shipdate'||v2_shipdate);
  66. dbms_output.put_line('ITEm id'|| v_itemid || 'item tot' || v_itemtot || 'AC' || v_actualprice);
  67. dbms_output.put_line('Total' || v_total);
  68.  
  69.  
  70. UPDATE transfer
  71. SET shipdate = v_shipdate
  72. WHERE ordid=proc_ordid;
  73. if(sql%rowcount=0) then
  74. raise exceptie;
  75. end if;
  76. exception
  77. when exceptie then
  78. dbms_output.put_line('ordid nu exista');
  79.  
  80. SELECT ordid, shipdate into v_ordid, v2_shipdate from transfer where ordid=proc_ordid;
  81. SELECT itemid, actualprice, itemtot into v_itemid, v_actualprice, v_itemtot from item where ordid=proc_ordid;
  82. SELECT total into v_total from ord where ordid=proc_ordid;
  83.  
  84. dbms_output.put_line('Ord id'||proc_ordid|| ', shipdate'||v2_shipdate);
  85. dbms_output.put_line('ITEm id'|| v_itemid || 'item tot' || v_itemtot || 'AC' || v_actualprice);
  86. dbms_output.put_line('Total' || v_total);
  87.  
  88. END p2;
  89. END test_trigger;
  90. /
  91. begin
  92. TEST_TRIGGER.P2(601, '10-JAN-86');
  93. end;
  94. /
  95. rollback;
  96.  
  97.  
  98.  
  99. -------------------------------------------1------------------------------------
  100. alter trigger monitor enable;
  101. alter trigger monitor disable;
  102. CREATE OR REPLACE TRIGGER monitor
  103. BEFORE UPDATE ON transfer
  104. FOR EACH ROW
  105. DECLARE
  106. v_ordid ord.ordid%type;
  107. v_qty item.qty%type;
  108. v_itemid item.itemid%type;
  109. v_actualprice item.actualprice%type;
  110. creditlimit number(30):=1500;
  111. v_total ord.total%TYPE;
  112. CURSOR maxCant IS
  113. SELECT max(qty), itemid, ordid
  114. FROM item;
  115. CURSOR totalCalc (v_ordidord item.ordid%type)IS
  116. SELECT total
  117. FROM ord
  118. where ordid=v_ordidord;
  119.  
  120. BEGIN
  121. IF UPDATING ('SHIPDATE') THEN
  122. IF :old.shipdate > :new.shipdate then --sau cu 2 variabile in care se scade nr de zile
  123. --pt old si new si se compara
  124. OPEN maxCant;
  125. LOOP
  126. FETCH maxCant into v_qty, v_itemid, v_ordid;
  127. EXIT WHEN maxCant%NOTFOUND;
  128.  
  129. UPDATE item
  130. SET ACTUALPRICE = ACTUALPRICE - ACTUALPRICE*0.3 where itemid = v_itemid;
  131. UPDATE item
  132. SET ITEMTOT = qty * actualprice where itemid = v_itemid;
  133. -- UPDATE ord
  134. -- SET total = sum(item.itemtot) where ordid = v_ordid;
  135. OPEN totalCalc(v_ordid);
  136. LOOP
  137. FETCH totalCalc INTO v_total;
  138. EXIT WHEN totalCalc%NOTFOUND;
  139. IF (v_total > creditlimit) then --in ce tabela e creditlimit??
  140. RAISE_APPLICATION_ERROR(-22, 'eroare');
  141. END IF;
  142. END LOOP;
  143. END LOOP;
  144. END IF;
  145. END IF;
  146. END;
  147. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement