Plsql 在循环之前显示数据
我有一个查询,用户输入一个项目编号,查询显示项目编号和项目描述,然后进入循环并显示数据库中每个项目编号的信息。在循环结束时,查询将根据显示的项目显示库存总量 在循环开始之前,如何显示项目编号和项目描述?除了那一部分,一切都很好 我想看看商品编号:5商品描述:衬衫。我没有看到任何关于项目编号和项目描述的数据 PL/SQL查询:Plsql 在循环之前显示数据,plsql,Plsql,我有一个查询,用户输入一个项目编号,查询显示项目编号和项目描述,然后进入循环并显示数据库中每个项目编号的信息。在循环结束时,查询将根据显示的项目显示库存总量 在循环开始之前,如何显示项目编号和项目描述?除了那一部分,一切都很好 我想看看商品编号:5商品描述:衬衫。我没有看到任何关于项目编号和项目描述的数据 PL/SQL查询: SET SERVEROUTPUT ON DECLARE CURSOR C1 IS SELECT items.items_numbers, item
SET SERVEROUTPUT ON
DECLARE
CURSOR C1
IS
SELECT items.items_numbers, items_description, items_size, items_price, items_qoh, sum(items_price*items_qoh) "Value" FROM inventories
JOIN items ON inventories.items_number=items.items_numbers
WHERE items.items_numbers='&enter_items_number'
GROUP BY items.items_numbers, items_description, items_size, items_color, items_price, items_qoh
ORDER BY items_price;
totalvalue NUMBER(8,2);
test1 C1%rowtype;
BEGIN
OPEN C1;
totalvalue:=0;
DBMS_OUTPUT.PUT_LINE('items ID: ' || test1.items_number || 'items Description: ' || test1.items_description);
close C1;
open C1;
LOOP
fetch C1 into test1;
exit when c1%notfound;
DBMS_OUTPUT.PUT_LINE('Size: ' || test1.items_size);
DBMS_OUTPUT.PUT_LINE('Price: ' || test1.items_price);
DBMS_OUTPUT.PUT_LINE('QOH: ' || test1.items_qoh);
DBMS_OUTPUT.PUT_LINE('Value: ' || test1.items_qoh*test1.items_price);
totalvalue:=totalvalue+test1.items_qoh*test1.items_price;
END LOOP;
DBMS_OUTPUT.PUT_LINE('TOTAL VALUE: ' || totalvalue);
END;
/
输出:
Item Number: Item Description:
Size: S
Price: 25.00
QOH: 25
Value: 625.0
Size: L
Color: Blue
Price: 30.00
QOH: 100
Value: 3000.0
TOTAL VALUE: 3625.0
就像从循环中打开的游标获取数据一样,您必须在循环之前获取数据才能打印数据。现在,您只需打开光标,然后再关闭它,而不需要从中提取。注意检查是否能够获取行(就像您在c1%未找到时所做的那样)