Advertisement
jelledebock

GemiddeldWinstPerCategorie

Dec 19th, 2014
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.88 KB | None | 0 0
  1. CREATE OR REPLACE PROCEDURE GEMIDDELDEWINSTPERCATEGORIE AS
  2. -- Cursor to loop through all categories
  3. CURSOR catcur IS SELECT cat.category_id, cat.category_name, AVG(pi.list_price-pi.min_price)/AVG(pi.min_price) AS average
  4. FROM product_information pi
  5.   INNER JOIN OE.order_items o ON o.product_id = pi.product_id
  6.   INNER JOIN OE.product_information pi ON pi.product_id = o.product_id
  7.   INNER JOIN OE.categories cat ON cat.category_id = pi.category_id
  8.   GROUP BY cat.category_id, cat.category_name
  9.   ORDER BY cat.category_name;
  10. BEGIN
  11.   BEGIN
  12.   FOR categori IN catcur LOOP
  13.     DBMS_OUTPUT.put_line('category '||categori.category_name||': '||categori.average);
  14.   END LOOP;
  15.   EXCEPTION WHEN ZERO_DIVIDE THEN
  16.       DBMS_OUTPUT.put_line('Category has badly priced item');
  17.   END;
  18. END GEMIDDELDEWINSTPERCATEGORIE;
  19. /*----Testapplicatie -----*/
  20. BEGIN
  21.   oe.gemiddeldewinstpercategorie();
  22. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement