I am not fluent with Oracle, and am testing out an auto-incrementing trigger required for older versions, where IDENTITY
is not yet available.
CREATE TABLE stuff (
id int PRIMARY KEY,
data varchar(255)
);
CREATE SEQUENCE stuff_sequence;
CREATE TRIGGER test
BEFORE INSERT ON stuff
FOR EACH ROW
BEGIN
SELECT stuff_sequence.nextval INTO :new.id FROM dual;
END;
INSERT INTO stuff(data) VALUES('test');
Using SQL Developer, I can run the CREATE TABLE
statement, and then the CREATE SEQUENCE
statement, but when I run the CREATE TRIGGER
statement, it highlights the INSERT
statement as well, and then complains about `Encountered the symbol "INSERT". Obviously, if I try to run the whole lot as a single script I get the same error.
What is happening here, and how do I fix it?