Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. -- Hamish Getty #16449057
  2. -- Question 1
  3.  
  4. SET SERVEROUTPUT ON;
  5.  
  6. DECLARE
  7. CURSOR emp_cursor IS
  8. SELECT e_number, e_name, e_address1, e_address3
  9. FROM employees;
  10.  
  11. temp_number employees.e_number%TYPE;
  12. temp_name employees.e_name%TYPE;
  13. temp_street employees.e_address1%TYPE;
  14. temp_city employees.e_address3%TYPE;
  15.  
  16. BEGIN
  17. OPEN emp_cursor;
  18. LOOP
  19. FETCH emp_cursor INTO temp_number, temp_name, temp_street, temp_city;
  20. EXIT WHEN emp_cursor%NOTFOUND;
  21. DBMS_OUTPUT.PUT_LINE('ID: '||temp_number);
  22. DBMS_OUTPUT.PUT_LINE('Name: '||temp_name);
  23. DBMS_OUTPUT.PUT_LINE('Address: '||temp_street||', '||temp_city||CHR(10));
  24. END LOOP;
  25. CLOSE emp_cursor;
  26. END;
  27. /
  28. SET SERVEROUTPUT OFF;
  29.  
  30. -- Question 2
  31.  
  32. SET SERVEROUTPUT ON;
  33.  
  34. DECLARE
  35. CURSOR emp_cursor IS
  36. SELECT e_number, e_name, e_address1, e_address2
  37. FROM employees
  38. WHERE e_address3 = 'Te Anautu';
  39.  
  40. temp_number employees.e_number%TYPE;
  41. temp_name employees.e_name%TYPE;
  42. temp_street employees.e_address1%TYPE;
  43. temp_suburb employees.e_address2%TYPE;
  44.  
  45. BEGIN
  46. OPEN emp_cursor;
  47. LOOP
  48. FETCH emp_cursor INTO temp_number, temp_name, temp_street, temp_suburb;
  49. EXIT WHEN emp_cursor%NOTFOUND;
  50. DBMS_OUTPUT.PUT_LINE('Employees from Te Anautu');
  51. DBMS_OUTPUT.PUT_LINE('ID: '||temp_number);
  52. DBMS_OUTPUT.PUT_LINE('Name: '||temp_name);
  53. DBMS_OUTPUT.PUT_LINE('Address: '||temp_street||', '||temp_suburb||CHR(10));
  54. END LOOP;
  55. CLOSE emp_cursor;
  56. END;
  57. /
  58. SET SERVEROUTPUT OFF;
  59.  
  60. -- Question 3
  61.  
  62. SET SERVEROUTPUT ON;
  63.  
  64. DECLARE
  65. CURSOR sup_cursor IS
  66. SELECT s_name, sup_number, p_description, p_unit_price
  67. FROM suppliers, employees, products
  68. ORDER BY p_description;
  69.  
  70. temp_name suppliers.s_name%TYPE;
  71. temp_number employees.sup_number%TYPE;
  72. temp_description products.p_description%TYPE;
  73. temp_price products.p_unit_price%TYPE;
  74.  
  75. BEGIN
  76. OPEN sup_cursor;
  77. LOOP
  78. FETCH sup_cursor INTO temp_name, temp_number, temp_description, temp_price;
  79. EXIT WHEN sup_cursor%NOTFOUND;
  80. DBMS_OUTPUT.PUT_LINE('Products Sold by Suppliers');
  81. DBMS_OUTPUT.PUT_LINE('Supplier: '||temp_name||', '||'Supplier ID: '||temp_number);
  82. DBMS_OUTPUT.PUT_LINE('Product: '||temp_description);
  83. DBMS_OUTPUT.PUT_LINE('Price: '||'$'||temp_price||' '||CHR(10));
  84. END LOOP;
  85. CLOSE sup_cursor;
  86. END;
  87. /
  88. SET SERVEROUTPUT OFF;
  89.  
  90. -- Question 4
  91. -- The "Update o_totals" from previous the AMICO lab seems to do nothing, therefore there is no order total?
  92.  
  93. SET SERVEROUTPUT ON;
  94.  
  95. DECLARE
  96. CURSOR ord_cursor IS
  97. SELECT o_number, e_name, o_order_date, o_total
  98. FROM orders, employees;
  99.  
  100. temp_number orders.o_number%TYPE;
  101. temp_name employees.e_name%TYPE;
  102. temp_date orders.o_order_date%TYPE;
  103. temp_total orders.o_total%TYPE;
  104.  
  105. BEGIN
  106. OPEN ord_cursor;
  107. LOOP
  108. FETCH ord_cursor INTO temp_number, temp_name, temp_date, temp_total;
  109. EXIT WHEN ord_cursor%NOTFOUND;
  110. DBMS_OUTPUT.PUT_LINE('Orders Greater Than $100');
  111. DBMS_OUTPUT.PUT_LINE('Order Number: '||temp_Number||', '||'Employee Name: '||temp_name);
  112. DBMS_OUTPUT.PUT_LINE('Date: '||temp_date);
  113. DBMS_OUTPUT.PUT_LINE('Total: '||'$'||temp_total||' '||CHR(10));
  114. END LOOP;
  115. CLOSE ord_cursor;
  116. END;
  117. /
  118. SET SERVEROUTPUT OFF;
  119.  
  120. -- Question 5
  121.  
  122. SET SERVEROUTPUT ON;
  123.  
  124. DECLARE
  125. CURSOR pay_cursor IS
  126. SELECT e_name, p_amount, p_date, o_number
  127. FROM employees, payments
  128. ORDER BY e_name;
  129.  
  130. temp_name employees.e_name%TYPE;
  131. temp_amount payments.p_amount%TYPE;
  132. temp_date payments.p_date%TYPE;
  133. temp_number payments.o_number%TYPE;
  134.  
  135. BEGIN
  136. OPEN pay_cursor;
  137. LOOP
  138. FETCH pay_cursor INTO temp_name, temp_amount, temp_date, temp_number;
  139. EXIT WHEN pay_cursor%NOTFOUND;
  140. DBMS_OUTPUT.PUT_LINE('Payments Made by Each Employee');
  141. DBMS_OUTPUT.PUT_LINE('Employee Name: '||temp_Name);
  142. DBMS_OUTPUT.PUT_LINE('Total: '||'$'||temp_amount);
  143. DBMS_OUTPUT.PUT_LINE('Date: '||temp_date);
  144. DBMS_OUTPUT.PUT_LINE('Order Number: '||temp_number||' '||CHR(10));
  145.  
  146. END LOOP;
  147. CLOSE pay_cursor;
  148. END;
  149. /
  150. SET SERVEROUTPUT OFF;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement