فهرست منبع

Create function to iterate over stock items

DricomDragon 5 سال پیش
والد
کامیت
c54dbdf1ad
1فایلهای تغییر یافته به همراه21 افزوده شده و 0 حذف شده
  1. 21 0
      SQL/plpgsql/create_supply_every_stock.sql

+ 21 - 0
SQL/plpgsql/create_supply_every_stock.sql

@@ -0,0 +1,21 @@
+CREATE OR REPLACE FUNCTION supply_every_stock(amount INTEGER) RETURNS void AS
+$$
+DECLARE
+    stoCursor CURSOR IS SELECT sto_quantity FROM Stock FOR UPDATE;
+    stoQuantity Stock.sto_quantity%TYPE;
+BEGIN
+    RAISE NOTICE 'Iterate on existing stocks only';
+
+    -- Iterate on storage
+    OPEN stoCursor;
+    LOOP
+        FETCH stoCursor INTO stoQuantity;
+        EXIT WHEN stoQuantity IS NULL;
+
+        RAISE NOTICE 'Supply %', amount;
+    END LOOP;
+    CLOSE stoCursor;
+    RAISE NOTICE 'End';
+END;
+$$
+LANGUAGE plpgsql;