这是我试图开始工作的下面的代码(PL / SQL)。结果是按名称(product_name)列出所有产品,并列出需求状态'列显示“需求低”'或者“需求量大”'根据订购的产品数量。 (如果数量> 2 =高)这是第一次使用匿名块。
My results are as follows (with just a snip) and what it should show is followed after that.
My results:
Product Name Demand Status
--------------- ---------------------
Intermediate Ski Boot Low Demand
Product Name Demand Status
--------------- ---------------------
Pro Ski Pole Low Demand
Product Name Demand Status
--------------- ---------------------
Intermediate Ski Boot Low Demand
Product Name Demand Status
--------------- --------------------
Correct results:
Product Name Demand Status
------------ -------------
Beginner's Ski Boot Low Demand
Intermediate Ski Boot High Demand
Pro Ski Boot Low Demand
Beginner's Ski Pole Low Demand
Thank you for your help.
declare
demand_status varchar2 (10);
quantity order_details.quantity%type;
cursor p_cur is
select product_name
from order_details, product
where product.product_id = order_details.product_id;
p_row p_cur%rowtype;
begin
open p_cur;
loop
fetch p_cur into p_row;
exit when p_cur%notfound;
if (quantity > 2 ) then demand_status := 'High Demand';
else demand_status := 'Low Demand';
dbms_output.put_line('Product Name'||' '||'Demand Status');
dbms_output.put_line('---------------'||' '||'---------------------');
dbms_output.put_line(p_row.product_name||' '||demand_status);
end if;
end loop;
close p_cur;
end;