我正在尝试计算可以用给定金额购买的商品总数。为此,我试图创建一个带有WHILE循环的块来增加项目的成本,直到满足美元值($ 100),但无法弄清楚如何正确计算循环。
{5, 1, 2}
答案 0 :(得分:0)
您的内容不正确。使用lv_totamt_num
计算价格。
还有其他小事。检查以下内容:
DECLARE
lv_totavail_num NUMBER(8,2) := 100;
lv_itemprice_num NUMBER(8,2) := 0;
lv_totamt_num NUMBER(8,2) := 0;
lv_loopnum_num NUMBER(8,2) := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE('Total Starting Amount: ' || lv_totavail_num);
SELECT price
INTO lv_itemprice_num
FROM BB_PRODUCT
WHERE IDPRODUCT = 4;
DBMS_OUTPUT.PUT_LINE('Price: ' || lv_itemprice_num);
WHILE lv_totavail_num >= lv_totamt_num LOOP
lv_loopnum_num := lv_loopnum_num + 1;
lv_totamt_num := lv_itemprice_num * lv_loopnum_num;
END LOOP;
lv_loopnum_num := lv_loopnum_num -1;
DBMS_OUTPUT.PUT_LINE('Number of Items Purchased that can be purchased: ' ||lv_loopnum_num );
DBMS_OUTPUT.PUT_LINE('Total Amount: '|| lv_loopnum_num * lv_itemprice_num);
END;