嗨,我有一個錯誤的問題。訂閱超出計數。我有一個創建訂單的程序(為了使代碼清晰,這部分被洗掉)。程式從籃子里挑選產品,然后在回圈中降低倉庫(可以有1個或多個倉庫)中特定產品的數量。你能解釋一下我做錯了什么嗎?非常感謝!
以下是我的程式主體:PROCEDURE cpr_create_order (pin_intCustomer IN customer.customer_id%TYPE,
pin_strPayment IN payment.payment_type%TYPE,
pin_strTransp IN transp.transp_type%TYPE。
pout_strErrorCode OUT NUMBER,
pout_strErrorMessage OUT VARCHAR2)
IS
lv_warehouse_balance NUMBER。
lv_intQuantity NUMBER;
lv_intOrder NUMBER。
TYPE collection_list IS TABLE OF NUMBER;
lv_products collection_list := collection_list()。
lv_quantities collection_list := collection_list();
lv_warehouses collection_list := collection_list();
lv_balances collection_list := collection_list();
BEGIN[/span
pout_strErrorCode := 0;
pout_strErrorMessage := ''/span>;
SAVEPOINT S1;
--從籃子里填充產品和數量的集合。
SELECT product_id, basket_quantity
BULK COLLECT INTO lv_products, lv_quantities
FROM basket
WHERE order_id IS NULL
order BY product_id。
FOR i IN 1.. lv_products.COUNT LOOP -- 1
-- 填充收集倉庫和實際產品余額。
SELECT warehouse_id, product_balance --1,2--5,10
BULK COLLECT INTO lv_warehouses, lv_balances
FROM 倉庫
WHERE product_id = lv_products(i)
ORDER BY warehouse_id。
lv_intQuantity := lv_quantities(i); --8
FOR j IN 1..lv_warehouses.COUNT LOOP
IF lv_intQuantity > 0 THEN.
SELECT product_balance
INTO lv_warehouse_balance
FROM warehouse
WHERE product_id = lv_products(i)
and warehouse_id = lv_warehouses(j)。
--按給定的數量降低倉庫中產品的余額。
IF lv_intQuantity < lv_warehouse_balance THEN --8 --10
UPDATE 倉庫
SET product_balance = product_balance - lv_intQuantity
WHERE product_id = lv_products(i)
and warehouse_id = lv_warehouses(j)。
lv_intQuantity := lv_intQuantity - lv_intQuantity; -0
-- 從倉庫移除產品。
ELSIF lv_intQuantity >= lv_warehouse_balance THEN。
DELETE FROM warehouse
WHERE product_id = lv_products(i)
and warehouse_id = lv_warehouses(j)。
lv_intQuantity := lv_intQuantity - lv_balances(i)。
END IF;
END IF;
END LOOP;
END LOOP;
例外情況
WHEN Other THEN
pout_strErrorCode := 1;
pout_strErrorMessage := substr(SQLERRM,
instr(SQLERRM, 'ORA') 11,
length(SQLERRM))。
ROLLBACK TO S1;
END cpr_create_order。
uj5u.com熱心網友回復:
這一行:
lv_intQuantity := lv_intQuantity - lv_balances(i) 。
應該是:
lv_intQuantity := lv_intQuantity - lv_balances(j) 。
lv_products和lv_quantities集合是由第一個批量集合填充的,所以它們有相同數量的成員,并且應該被同一個變數i索引--你正在這樣做。
lv_warehouses和lv_balances集合是由第二個批量集合填充的,所以它們有相同數量的成員,并且應該被同一個變數j索引。
你不應該參考lv_balances(i) - 它有時會給出一個結果,但它不會是你所期望的,當j低于i時,它會得到這個錯誤,因為在該集合中沒有索引為i的成員。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/334012.html
標籤:
上一篇:永久地改變DIV的背景顏色
下一篇:SQLITE記錄不更新
