Advertisement
jelledebock

ProductenPerKlant

Dec 19th, 2014
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.23 KB | None | 0 0
  1. CREATE OR REPLACE
  2. PROCEDURE ProductenPerKlant AS
  3. --First cursor: loop through all customers
  4.   CURSOR customcursor IS
  5.     SELECT customer_id, cust_first_name, cust_last_name FROM oe.customers;
  6. --Second cursor: loop through all customer's orders
  7.   CURSOR ordercursor (customer customcursor%ROWTYPE) IS
  8.     SELECT o.order_id FROM oe.orders o
  9.     WHERE customer.customer_id = o.customer_id;
  10. --Third cursor: loop through all customer's order's items
  11.   CURSOR productcursor (item ordercursor%ROWTYPE) IS
  12.     SELECT i.product_id, pi.product_name, i.unit_price, i.quantity FROM oe.order_items i
  13.     INNER JOIN oe.product_information pi ON i.product_id = pi.product_id
  14.     WHERE i.order_id = item.order_id;
  15. BEGIN
  16.   FOR customer IN customcursor LOOP
  17.     DBMS_OUTPUT.put_line('Customer '||customer.customer_id||', '
  18.         ||customer.cust_first_name||' '||customer.cust_last_name);
  19.     FOR ordern IN ordercursor(customer) LOOP
  20.       FOR product IN productcursor(ordern) LOOP
  21.         DBMS_OUTPUT.put_line(product.product_id || ' ' || product.product_name
  22.                 || ' ' || product.unit_price || ' ' || product.quantity);
  23.       END LOOP;
  24.     END LOOP;
  25.   END LOOP;
  26. END;
  27. /
  28. /*---- Testapplication ---- */
  29. BEGIN
  30. productenperklant();
  31. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement