-1

I'm trying to create a trigger for auto incrementing id value in Oracle. Here is the code that I've tried to use

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

Alexander Tolkachev
  • 227
  • 1
  • 4
  • 15

2 Answers2

2

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

Community
  • 1
  • 1
0

; missing after from dummy?

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;
Kacper
  • 4,798
  • 2
  • 19
  • 34