Alexander  Tolkachev Alexander Tolkachev - 1 month ago 9
SQL Question

Encountered the symbol end of file. Oracle

What is wrong with my code?

create or replace
trigger themes_on_insert
before insert on THEME
for each row
begin
select themes_sequence.nextval
into :new.ID
from dummy
end;



Error(5,4): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ( begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge

Answer

Statements must be ended with a ; and the whole PL/SQL block must be ended with a /

create or replace trigger themes_on_insert
  before insert on THEME
  for each row
begin
  select themes_sequence.nextval
  into :new.ID
  from dummy; --<< missing ; here
end;
/ 

The select is actually not necessary, this can be simplified to:

create or replace trigger themes_on_insert
  before insert on THEME
  for each row
begin
  :new.ID := themes_sequence.nextval;
end;
/ 

For details on why the / is needed see here