WHILE循环数学逻辑

时间:2015-09-20 19:09:32

标签: sql oracle while-loop

DECLARE
totalSpendAmt NUMBER(6,2) := 100;
itemPrice NUMBER(6,2) := 129.99;
qty NUMBER(6,2) :=1;
BEGIN
WHILE 
totalspendamt >= itemprice LOOP 
totalspendamt := totalspendamt - itemprice; 
qty := qty + 1; 
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total quantity can be purchased '||qty);
DBMS_OUTPUT.PUT_LINE('Total amount spend '||qty * itemprice);
END;

以上代码计算可以用给定金额购买的指定商品的总数量。我一直得到“可以购买总量1.总金额129.99”答案应为0.任何建议都将受到赞赏。

0 个答案:

没有答案