Search code examples
sqloracle-databaseddlora-00907

ORA-00907: missing right parenthesis SQL Developer


I need to know why I get a parenthesis error in this part of the code.

CREATE TABLE CIUDAD(
COD_CIUDAD NUMBER(3) CONSTRAINT CIUDAD_PK PRIMARY KEY (COD_CIUDAD),
NOMBRE VARCHAR2(20) CONSTRAINT NOTNULL_NOMBRE NOT NULL,
NOMBRE_REGION VARCHAR(20) CONSTRAINT NOTNULL_NOMBRE_REGION NOT NULL
);

Solution

  • When you are using an in-line constraint, the PRIMARY KEY automatically refers to the column being declared. Hence, the (COD_CIUDAD) is not accepted.

    Try this:

    CREATE TABLE CIUDAD (
        COD_CIUDAD NUMBER(3) CONSTRAINT CIUDAD_PK PRIMARY KEY,
        NOMBRE VARCHAR2(20) CONSTRAINT NOTNULL_NOMBRE NOT NULL,
        NOMBRE_REGION VARCHAR2(20) CONSTRAINT NOTNULL_NOMBRE_REGION NOT NULL
    );
    

    I changed the type of NOMBRE_REGION to VARCHAR2().