Search code examples
sqloracle-databaseoracle-sqldeveloperoracle12c

Missing right parenthesis after (or before) default 0, Oracle


I am trying to create a table with oracle SQL two columns of the table should have default value and should not be NULL.

I am getting the error you can see below, but i am not able to understand it because the are no parenthesis to be closed there !!!!

CREATE TABLE ENCUENTROS (
  2  elocal constraint clave_extrana_equipos references equipos(code) not null enable,
  3  evisitante constraint clave_extrana_equipos references equipos(code) not null enable,
  4  fecha date,
  5  plocal number constraint plocal_mayor_cero check (plocal > 0) default 0 not null enable,
  6  pvisitante number constraint pvisitante_mayor_cero check (pvisitante > 0) default 0 not null enable);
plocal number constraint plocal_mayor_cero check (plocal > 0) default 0 not null enable,
                                                              *
ERROR at line 5:
ORA-00907: missing right parenthesis

Error solved:

enter image description here


Solution

  • This code worked for me:

    create table encuentros (
      elocal number not null 
        constraint clave_extrana_equipos_1 references equipos(code) enable,
      evisitante number not null 
        constraint clave_extrana_equipos_2 references equipos(code) enable,
      fecha date,
      plocal number default 0 not null 
        constraint plocal_mayor_cero check (plocal >= 0)  enable,
      pvisitante number default 0 not null 
        constraint pvisitante_mayor_cero check (pvisitante >= 0) enable);
    

    There were several issues:

    • name clave_extrana_equipos for constraints was used twice. Use two different names,
    • columns elocal and evisitante had no type specified,
    • write default 0 not null after type specification, before constraint.

    Edit:

    As @APC noticed type specification for first two columns is not needed here.