Piotr Zaborowski
Piotr Zaborowski

Reputation: 33

pl/sql Cursor error ORA-06550 ORA-00905 Cursor will not compile because of a missing keyword. I don't really know which keyword I am missing

I'm trying to write a simple cursor that will display all sales from SALES table in a form (seller surname) sold a product to (customer surname)

Here's my cursor:

DECLARE
    l_sellersurname
        seller.sellersurname%type;
    l_customersurname
        customer.customersurname%type;
        l_sale
            sale.saleid%type;
CURSOR c IS 
select * FROM SALE
BEGIN 
    for sale in c loop

  DBMS_OUTPUT.put_line (
     l_sellersurname || 
     ' sold a product to a Mr/Ms. ' || 
     l_customersurname);
end loop;
END;

I'm getting an error:

ORA-06550: line 11, column 6: PL/SQL: ORA-00905: missing keyword

Anyone can give me any tips how to fix it?

Upvotes: 1

Views: 688

Answers (2)

William Robertson
William Robertson

Reputation: 15991

Perhaps you wanted this:

begin
    for r in (
        select * from sale
    )
    loop
        dbms_output.put_line(r.sellersurname || ' sold a product to a Mr/Ms. ' || r.customersurname);
    end loop;
end;

Upvotes: 0

VBoka
VBoka

Reputation: 9083

Add ; at the end of the cursor:

CURSOR c IS 
select * FROM SALE;

Also please note that you are not inserting nothing in your variables l_sellersurname, l_customersurname, l_sale. I am sure that is just a beginning of some procedure or function...

Let's say it is a part of procedure here is a demo showing that after you add ; after the cursor all will work fine: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=8c8cc10ac215dbbf6020070be1ef69e4

Upvotes: 2

Related Questions