问题是,循环没有根据需要进行计数:
我需要举例:100%的DVD价格等于64 $ 95%是60.8 $ 在90时,它必须取原始价格(64 $)并从该价格中赚取90%,但是,他从最近的价格(60.8 $)开始计算,而他在做90%。
create or replace procedure PR_PRICE
is V_PRICE DVD.AMOUNT_PRICE_DVD%type;
p_counter number(3):=100;
begin
select AMOUNT_PRICE_DVD into V_PRICE
from DVD
where TITLE_DVD like '%pop';
-- p_counter :=100;
while p_counter >= 80 loop
V_PRICE := p_counter*V_PRICE/ 100;
dbms_output.put_line('The price of DVD at ' || p_counter ||'% is: ' || V_PRICE ||'$');
p_counter := p_counter-5;
end loop;
end PR_PRICE;
/
答案 0 :(得分:1)
而不是覆盖v_price
,而是为折后价格创建一个不同的变量:
create or replace procedure PR_PRICE
is
V_PRICE DVD.AMOUNT_PRICE_DVD%type;
V_DISCOUNT_PRICE DVD.AMOUNT_PRICE_DVD%type; -- Declared here
p_counter number(3):=100;
begin
select AMOUNT_PRICE_DVD into V_PRICE
from DVD
where TITLE_DVD like '%pop';
p_counter :=100;
while p_counter >= 80 loop
V_DISCOUNT_PRICE := p_counter*V_PRICE/ 100; -- Calculated here
dbms_output.put_line('The price of DVD at ' || p_counter ||'% is: ' || V_DISCOUNT_PRICE ||'$');
p_counter := p_counter-5;
end loop;
end PR_PRICE;