Search code examples
oracle-databaseplsqlplsqldeveloper

select into causes error ORA-00933: SQL command not properly ended


I have just started trying on writing som PL SQL code so the answer to this question is probable quite easy. I am getting the following error ORA-00933: SQL command not properly ended when executing the code below.

What i am trying to do is to summarize all the values in in the quantity column, return it to variable "stocklvl" which is what the function should return.

Could you guys please advise what i am missing?

I am currently working with the examples found on oracletutorial, and a similar example is working for me but cannot find the error on these lines of code.

Thanks for your help in advance.


create or replace function get_stocklvl 

return number

is 
stocklvl number := 0;


begin
 
select sum (quantity) 
INTO stocklvl
from inventories
where product_id = 102 --(Tried both with '' and without)

return stocklvl;
end;

Solution

  • You forgot semicolon

    create or replace function get_stocklvl 
    
    return number
    
    is 
    stocklvl number := 0;
    
    
    begin
     
    select sum (quantity) 
    INTO stocklvl
    from inventories
    where product_id = 102; --(Tried both with '' and without)
    
    return stocklvl;
    end;