1
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;
4

3 回答 3

1
  1. You have a colon after 0.15. That should be a semi-colon.
  2. Numeric literals should not have embedded commas.
  3. Your IF statement comes before you've fetched anything from the cursor. Perhaps you want that statement to be inside the loop after the EXIT statement?
  4. Your IF statement is referring to a variable price that does not exist. Perhaps you want to refer to emp_row.price?
  5. The syntax for an IF statement is IF ... THEN ... ELSIF ... END IF. You are missing the END IF and you either want to combine the else if into a single elsif or have two separate IF statements and two separate END IF statements.

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 回答