Search code examples
sqloracleplsqlcursor

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?


Solution

  • 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