sql错误ora-00907缺少右括号创建表

时间:2016-03-28 00:37:38

标签: sql oracle ora-00907

我正在创建一个这样的表,

CREATE TABLE ARTIST (

    ArtistID            Int             NOT NULL IDENTITY(1,1),
    LastName            Char(25)        NOT NULL,
    FirstName           Char(25)        NOT NULL, 
    Nationality         Char(30)        NULL,
    DateOfBirth         Numeric(4)      NULL, 
    DateDeceased        Numeric(4)      NULL,
    CONSTRAINT  ArtistPK            PRIMARY KEY(ArtistID),
    CONSTRAINT  ArtistAK1           UNIQUE(LastName, FirstName),    
    CONSTRAINT  BirthValuesCheck    CHECK (DateOfBirth < DateDeceased),
    CONSTRAINT  ValidBirthYear      CHECK
            (DateOfBirth LIKE '[1-2][0-9][0-9][0-9]'),
    CONSTRAINT  ValidDeathYear      CHECK
            (DateDeceased LIKE '[1-2][0-9][0-9][0-9]')
);

我收到此错误:

  

错误报告 - SQL错误:ORA-00907:缺少右括号   00907. 00000 - &#34;错过右括号&#34;

知道为什么吗?

1 个答案:

答案 0 :(得分:3)

Oracle 12c syntax for identity columns是:

GENERATED [ ALWAYS | BY DEFAULT [ ON NULL ] ]
AS IDENTITY [ ( identity_options ) ]

如果您使用的是Oracle 11或更低版本,那么您不能拥有IDENTITY列,并且必须使用序列,但假设您使用的是12c,则需要:

CREATE TABLE ARTIST (
    ArtistID            Int             NOT NULL GENERATED ALWAYS AS IDENTITY,
    LastName            Char(25)        NOT NULL,
    FirstName           Char(25)        NOT NULL, 
    Nationality         Char(30)        NULL,
    DateOfBirth         Numeric(4)      NULL, 
    DateDeceased        Numeric(4)      NULL,
    CONSTRAINT  ArtistPK            PRIMARY KEY(ArtistID),
    CONSTRAINT  ArtistAK1           UNIQUE(LastName, FirstName),    
    CONSTRAINT  BirthValuesCheck    CHECK (DateOfBirth < DateDeceased),
    CONSTRAINT  ValidBirthYear      CHECK
            (DateOfBirth LIKE '[1-2][0-9][0-9][0-9]'),
    CONSTRAINT  ValidDeathYear      CHECK
            (DateDeceased LIKE '[1-2][0-9][0-9][0-9]')
);