Advertisement
jelledebock

Oefening3Procedure

Dec 19th, 2014
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.01 KB | None | 0 0
  1. CREATE OR REPLACE
  2. PROCEDURE ProductenPerWareHouse AS
  3. --First cursor: get all warehouses
  4. CURSOR warehousec IS SELECT * FROM OE.Warehouses;
  5. --Needed in next cursor
  6. warehouserow warehousec%ROWTYPE;
  7. --Second cursor: get all distinct ordered products for a specific warehouse
  8. CURSOR productc (param warehouserow%TYPE) IS
  9. SELECT DISTINCT o.product_id, pd.product_name FROM OE.Order_Items o
  10. INNER JOIN OE.Inventories i ON i.product_id = o.product_id
  11. INNER JOIN OE.Product_information pd ON pd.product_id = o.product_id
  12. WHERE i.warehouse_id = param.warehouse_id
  13. ORDER BY o.product_id ASC;
  14.  
  15. productrow productc%ROWTYPE;
  16. BEGIN
  17. FOR warehouserow IN warehousec
  18. LOOP
  19.   DBMS_OUTPUT.PUT_LINE('Warehouse ' || warehouserow.warehouse_id || ', '
  20.         || warehouserow.warehouse_name);
  21.   FOR productrow IN productc(warehouserow)
  22.   LOOP
  23.   DBMS_OUTPUT.put_line(productrow.product_id || ' '
  24.         || productrow.product_name);
  25.   END LOOP;
  26. END LOOP;
  27. END;
  28. /
  29. /*---- Testprogramma ---*/
  30. BEGIN
  31. oe.productenperwarehouse();
  32. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement