ORA-00906:"missing left parenthesis" in sql developer - sql

When I tried to create this table, this error appeared me and I don't know why
CREATE TABLE Empregado(
cod_empregado INTEGER,
cod_supervisor INTEGER,
cod_armazem INTEGER,
nome VARCHAR(40) NOT NULL,
morada VARCHAR(40) NOT NULL,
salario_semanal NUMERIC(*,2) NOT NULL,
formacao VARCHAR(40) NOT NULL,
CONSTRAINT pk_Empregado_cod_empregado PRIMARY KEY,
CONSTRAINT fk_Empregado_cod_supervisor FOREIGN KEY(cod_supervisor)
REFERENCES Empregado(cod_supervisor),
CONSTRAINT fk_Empregado_cod_armazem FOREIGN KEY(cod_armazem) REFERENCES
Armazem(cod_armazem)
);
And this is the output
Error report -
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:

The issue that throws out the error you are seeing is caused by the PRIMARY KEY constraint: you didn't state WHICH column is the primary key. The PK column must be in parentheses; the opening parenthesis is missing (along with the rest), and that is the first syntax violation Oracle sees.
After you fix that, you will get another error, on the first foreign key, because you are referencing the wrong table (or if it should reference the same table you are creating, you are referencing the wrong COLUMN).

Related

Assistance with "Missing right parenthesis" error

The following statement fails with an error "missing right parenthesis":
CREATE TABLE STUDENT
( Student# NUMBER(9),
FirstName VARCHAR2(52),
LastName VARCHAR2(50),
DeptID NUMBER(9) NOT NULL,
ProjectID NUMBER(5,2) NOT NULL,
PCID NUMBER(10) NOT NULL,
PR# NUMBER(10) NOT NULL,
Email VARCHAR(50)
CONSTRAINT student_student#_pk PRIMARY KEY (student#),
CONSTRAINT student_deptid_fk FOREIGN KEY (deptid)
REFERENCES department (deptid),
CONSTRAINT student_pcid_fk FOREIGN KEY (pcid)
REFERENCES projectcourse (pcid) ,
CONSTRAINT student_project#_fk FOREIGN KEY (project#)
REFERENCES project (project#),
CONSTRAINT student_pr#_fk FOREIGN KEY (pr#)
REFRENCES projectregisteration (pr#));
EDITED
After a few corrections I'm still getting the ORA-00942: table or view does not exist error. Below is what my code currently looks like. Any further suggestions will be appreciated.
CREATE TABLE STUDENT
( Student# NUMBER(9),
FirstName VARCHAR2(52),
LastName VARCHAR2(50),
DeptID NUMBER(9) NOT NULL,
Project# NUMBER(5,2) NOT NULL,
PCID NUMBER(10) NOT NULL,
PR# NUMBER(10) NOT NULL,
Email VARCHAR2(150),
CONSTRAINT student_student#_pk PRIMARY KEY (student#),
CONSTRAINT student_deptid_fk FOREIGN KEY (deptid)
REFERENCES department (deptid),
CONSTRAINT student_pcid_fk FOREIGN KEY (pcid)
REFERENCES projectcourse (pcid) ,
CONSTRAINT student_project#_fk FOREIGN KEY (project#)
REFERENCES project (project#),
CONSTRAINT student_pr#_fk FOREIGN KEY (pr#)
REFERENCES projectregisteration (pr#));
A , is missing after Email VARCHAR(50). There's a typo, REFRENCES instead of REFERENCES. And in CONSTRAINT student_project#_fk FOREIGN KEY (project#), the column project# isn't in the list of columns above.
The Oracle compiler throws missing right parenthesis when we have made a syntax error in our code.
Obviously the first thing to check is that we have a right parenthesis for every left parenthesis; this is easy if we're using an editing tool which supports bracket matching (say by highlighting matching pairs).
But often we have matched all the brackets, so why do we get this error? It happens when we have missed something, and the compiler interprets that as a missing bracket.
For instance a valid CREATE TABLE statement consists of a number of clauses defining columns and constraints, enclosed by a pair of brackets (optionally followed by a storage clause). The important things is that the column and constraint clauses are all separated by commas. In your statement you have missed the comma after the Email VARCHAR(50). The compiler interprets this as the end of the statement and expects a right parenthesis. But your statement kicks off a constraint clause instead. Hence the error message.
It would be neat if the compiler was clever enough to identify a missing comma, but that would require the compiler to additional work and the compiler writers opted to outsource that work to us instead :)
Looking at your last foreign key constraint, you have the table name entered as "projectregisteration". Are you certain that's correct? Please check that the table name is as you've typed it, and not "projectregistration" (without the "e" after the first "t" in "registration").
If I create all the tables as shown in your second CREATE TABLE statement, then the statement executes without a problem. However, if I make the last table PROJECTREGISTRATION (correct spelling of "registration") instead of PROJECTREGISTERATION (as shown in your CREATE TABLE) then the CREATE TABLE fails with ORA-00942: table or view does not exist, just as you stated.
So I suspect it's a simple typo.
dbfiddle here
Best of luck.

SQL error missing right parentheses

I am new to SQL and I am doing an assignment for class. I do not understand what is wrong with the statement below.
CREATE TABLE APP_DEGREE
(DEGREE_ID varchar (6) NOT NULL,
TITLE varchar (3O),
INSTITUTION varchar (30),
App_ID varchar (6) NOT NULL,
CONSTRAINT constr_degree_pk PRIMARY KEY (DEGREE_ID),
CONSTRAINT constr_degree_fk FOREIGN KEY (App_ID) REFERENCES APPLICANT (App_ID)
);
When I run the script I receive this error:
Error report -
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Thank you for your help!
Typo: TITLE varchar (30) and not TITLE varchar(3O)
CREATE TABLE APP_DEGREE(
DEGREE_ID varchar(6) NOT NULL,
TITLE varchar(30),
INSTITUTION varchar(30),
App_ID varchar(6) NOT NULL,
CONSTRAINT constr_degree_pk PRIMARY KEY(DEGREE_ID),
CONSTRAINT constr_degree_fk FOREIGN KEY(App_ID) REFERENCES APPLICANT(App_ID)
);
Edit: The "O" instead "0". Use an IDE, you will see this kind of errors instantly. Also the "`" string delimiter to have not to deal with reserved sql keywords like "order" as field name.

SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"

I don't know what is wrong with this syntax.
create table table3 (
id number,
id_table1 number,
id_table2 number,
area varchar2(130) not null,
status varchar2(20),
additional_info varchar2(100),
data date default sysdate,
responsable varchar2(60) not null,
constraint ck_status_contract check(status in('value1','value2','value3')),
constraint fk_id_table1 references table1 on delete set null,
constraint fk_id_table2 references table2 on delete set null,
constraint pk_id_contract primary key(id)
);
The result is:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
I use OracleXE112_Win64.
On your FK you need to specify the columns affected on both ends
CONSTRAINT fk_column
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1,..)
You have missed to add foreign key references properly.
To specify foreign key constraint, you should either use inline
CONSTRAINT [constraint_name] FOREIGN KEY(customer_id) REFERENCES [master_table_name]([master_column_name])
See more example from this tutorial: What is foreign key?
Resource Link:
SQL Error: ORA-00907: missing right parenthesis

Error in SQL Developer during creating tables

I'm trying to create 3 tables using SQL Developer and have an error. Can't undersand why it happens.
Create table Album
(
"alb_code" integer primary key,
"alb_name" char(50),
"publ" char(50),
"publ_date" date not null
);
Create table Song
(
"song_code" integer primary key,
"song_name" char(50),
"auth" char(50),
"year" integer,
"style" char(30)
);
Create table Song_from_Album
(
"in_alb_code" integer primary key,
"time" float,
"no" integer,
FOREIGN KEY REFERENCES Song("song_code"),
FOREIGN KEY REFERENCES Album("alb_code")
);
I get an error:
Error starting at line : 1 in command -
Create table Album
(
"alb_code" integer primary key,
"alb_name" char(50),
"publ" char(50),
"publ_date" date not null
)
Error at Command Line : 1 Column : 14
Error report -
SQL Error: ORA-00955: имя уже задействовано для существующего объекта
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 8 in command -
Create table Song
(
"song_code" integer primary key,
"song_name" char(50),
"auth" char(50),
"year" integer,
"style" char(30)
)
Error at Command Line : 8 Column : 14
Error report -
SQL Error: ORA-00955: имя уже задействовано для существующего объекта
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line : 16 in command -
Create table Song_from_Album
(
"in_alb_code" integer primary key,
"time" float,
"no" integer,
FOREIGN KEY REFERENCES Song("song_code"),
FOREIGN KEY REFERENCES Album("alb_code")
)
Error at Command Line : 21 Column : 15
Error report -
SQL Error: ORA-00906: отсутствует левая скобка
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
The first two tables are getting created, but third table has error.
Drop the tables and recreate with correction to third table syntax
The error "missing left parenthesis" is with the foreign key constraint declaration,
Use this instead
CONSTRAINT fk_no FOREIGN KEY ("no") REFERENCES Song("song_code"),
CONSTRAINT fk_alb_code FOREIGN KEY ("in_alb_code") REFERENCES Album("alb_code")
With this change, Song_Album table declaration will be like this
Create table Song_from_Album
(
"in_alb_code" integer primary key,
"time" float,
"no" integer,
CONSTRAINT fk_no FOREIGN KEY ("no") REFERENCES Song("song_code"),
CONSTRAINT fk_alb_code FOREIGN KEY ("in_alb_code") REFERENCES Album("alb_code")
);

Oracle create table with foreign key error - Invalid Identifier

I'm getting an error saying invalid identifier when I try to add this table. Its been bugging me for too long now so I thought I'd ask.
CREATE TABLE HORSE
(
horse_id numeric PRIMARY KEY,
horse_name character(30) not null,
horse_gender character(1) not null,
horse_height decimal not null,
horse_image character(40),
CONSTRAINT horse_breed FOREIGN KEY (breed_id) REFERENCES breed(breed_id)
);
The error message is;
Error at Command Line:34 Column:37
Error report:
SQL Error: ORA-00904: "BREED_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Thanks and sorry for asking what is probably a really dumb question.
You need breed_id in HORSE table
CREATE TABLE HORSE
(
horse_id numeric PRIMARY KEY,
horse_name character(30) not null,
horse_gender character(1) not null,
horse_height decimal not null,
horse_image character(40),
breed_id numeric null
CONSTRAINT horse_breed FOREIGN KEY (breed_id) REFERENCES breed(breed_id)
);