set serveroutput on;
Declare
cursor emp_cursor is select orderline.orderid, sum(product.productstandardprice * orderline.orderedquantity) AS price from orderline, Product WHERE orderline.Productid = Product.Productid group by orderline.orderid;
emp_row emp_cursor%rowtype;
Begin
open emp_cursor;
if (price < 2,000)
then price := 2,000 * 0.15:
else if (price >= 2,000)
then price := 2,000 * 0.20;
loop
fetch emp_cursor into emp_row;
exit when emp_cursor%notfound;
dbms_output.put_line(emp_row.orderid || ' ' || emp_row.price);
end loop;
close emp_cursor;
End;
2590 次
3 回答
1
- You have a colon after 0.15. That should be a semi-colon.
- Numeric literals should not have embedded commas.
- Your
IFstatement comes before you've fetched anything from the cursor. Perhaps you want that statement to be inside the loop after theEXITstatement? - Your
IFstatement is referring to a variablepricethat does not exist. Perhaps you want to refer toemp_row.price? - The syntax for an
IFstatement isIF ... THEN ... ELSIF ... END IF. You are missing theEND IFand you either want to combine theelse ifinto a singleelsifor have two separateIFstatements and two separateEND IFstatements.
There may be additional syntax errors that I'm not seeing. It is always helpful to post the DDL to create your tables, the DML to populate the data, and the expected results. That allows us to test on our system and makes it more likely that we'll catch all the errors.
于 2013-11-15T03:29:07.237 回答
0
if-else 语句以END IF;
尝试将其放入并运行。
于 2013-11-15T06:01:44.940 回答
0
希望这可以帮助...
Declare
cursor emp_cursor is select orderline.orderid, sum(product.productstandardprice * orderline.orderedquantity) AS price from orderline, Product WHERE orderline.Productid = Product.Productid group by orderline.orderid;
emp_row emp_cursor%rowtype;
Begin
open emp_cursor;
loop
fetch emp_cursor into emp_row;
exit when emp_cursor%notfound;
if emp_row.price < 2000 then
emp_row.price := 2000 * 0.15;
elsif emp_row.price >= 2000 then
emp_row.price := 2000 * 0.20;
end if;
dbms_output.put_line(emp_row.orderid || ' ' || emp_row.price);
end loop;
close emp_cursor;
End;
于 2013-11-20T06:22:14.940 回答