why is auto-increment trigger creation in oracle failing?

124 views Asked by At

Using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production I am trying to create a trigger for auto-incrementation. This solution is discussed all over the web, and is pretty much conceded to be the standard auto-increment solution for Oracle. For example this Stack Overflow article seems to be definitive.

So following the lead, we have this:

If you are using Oracle 11.1 or later, you can simplify the trigger a bit

CREATE OR REPLACE TRIGGER trigger_name
  BEFORE INSERT ON table_name
  FOR EACH ROW
BEGIN
  :new.primary_key_column := name_of_sequence.nextval;
END;

I follow this recipe exactly. In my script, I create the sequence. I create the table.

But every time script gets to creating the trigger, it seems to be entering an endless loop it never gets out of. The trigger is never created and any SQL statements below this in the script never get executed.

I've stared at this a million times. My copy is exact. What could I be doing wrong?

1

There are 1 answers

1
Randy On BEST ANSWER

try with a trailing slash

CREATE OR REPLACE TRIGGER trigger_name
  BEFORE INSERT ON table_name
  FOR EACH ROW
BEGIN
  :new.primary_key_column := name_of_sequence.nextval;
END;
/