0

I'm using Oracle's SQLDeveloper and trying to create some tables. My goal is to create a simple table, for example, with an auto-generated id together with a description.

CREATE TABLE xpto (
id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
description VARCHAR2(200) NOT NULL
);

I'm getting:

Error report -
SQL Error: ORA-02000: missing ( keyword
02000. 00000 -  "missing %s keyword"

Any idea what I might be doing wrong? Thanks in advance!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
João Tiago
  • 45
  • 1
  • 6

1 Answers1

1

Identity columns is a feature supported by Oracle from version 12c.
In Oracle 11 it does not work, you must use a sequence and a trigger, in this way:

CREATE TABLE xpto (
id NUMBER PRIMARY KEY,
description VARCHAR2(200) NOT NULL
);

CREATE SEQUENCE xpto_seq;

set define off
CREATE OR REPLACE TRIGGER xpto_id 
BEFORE INSERT ON xpto 
FOR EACH ROW
WHEN ( new.id IS NULL )
BEGIN
   :new.id := xpto_seq.nextval;
END;
/
krokodilko
  • 35,300
  • 7
  • 55
  • 79