SQL error missing right parentheses - sql

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.

Related

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

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).

Error report - ORA-00904: : invalid identifier 00904. 00000 - "%s: invalid identifier"

This is my SQL Oracle script and I cannot figure out why I keep getting the following error when I try and run this code:
I keep getting this exact code on each table I try to run. Can anyone point me in the right direction as to why my code will not run? I have tried researching this myself ALL DAY LONG and cant get it.**
Error starting at line : 12 in command -
CREATE TABLE COURSE (
CRS_CODE VARCHAR (8) NOT NULL,
CRS_DESCRIPTION VARCHAR (35) NOT NULL,
CONSTRAINT CRS_CREDIT NOT NULL,
CHECK (CRS_CREDIT IN (1,2,3,4)),
PRIMARY KEY (CRS_CODE))
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
SQL>
**CODE BEFORE ERROR:**
/* This script file creates the following tables:*/
/*COURSE, CLASS, ENROLL, STUDENT */
set echo on;
set serveroutput on ;
/*DROP TABLE COURSE;
DROP TABLE CLASS;
DROP TABLE STUDENT;
DROP TABLE ENROLL;*/
CREATE TABLE COURSE (
CRS_CODE VARCHAR (8) NOT NULL,
CRS_DESCRIPTION VARCHAR (35) NOT NULL,
CONSTRAINT CRS_CREDIT NOT NULL,
CHECK (CRS_CREDIT IN (1,2,3,4)),
PRIMARY KEY (CRS_CODE));
CREATE TABLE CLASS (
CLASS_CODE NUMBER (5) NOT NULL,
CONSTRAINT CLASS_SECTION_Ck NOT NULL,
CLASS_TIME VARCHAR (25) NOT NULL,
CLASS_ROOM CHAR (6),
CHECK (CLASS_SECTION IN (1,2,3,4,5,6,7,8)),
PRIMARY KEY (CLASS_CODE),
FOREIGN KEY (CRS_CODE) REFERENCES COURSE (CRS_CODE));
CREATE TABLE STUDENT (
STU_NUM INTEGER NOT NULL,
STU_LNAME VARCHAR (25) NOT NULL,
STU_FNAME VARCHAR (20) NOT NULL,
STU_INIT CHAR (1),
STU_DOB DATE NOT NULL,
CONSTRAINTS STU_HRS_Ck DEFAULT 0 NOT NULL,
STU_CLASS CHARACTER(2) REFERENCES "Fr", "So", "Jr", "Gr" NOT NULL,
CONSTRAINT STU_GPA_Ck DEFAULT 0.00 NOT NULL,
STU_PHONE VARCHAR (4) NOT NULL,
PRIMARY KEY (STU_NUM),
CHECK (STU_HRS <= 0),
CHECK (STU_HRS >= 1000),
CHECK (STU_GPA BETWEEN 0.00 AND 4.00));
CREATE TABLE ENROLL (
ENROLL_GRADE_Ck VARCHAR (1) REFERENCES "A","B","C","D","F","I","W", "Z", DEFAULT Z NOT NULL,
FOREIGN KEY (STU_NUM) REFERENCES STUDENT (STU_NUM),
FOREIGN KEY (CLASS_CODE) REFERENCES CLASS (CLASS_CODE),
PRIMARY KEY (CLASS_CODE));
commit;
It is not clear from your question whether you are trying to create a COLUMN level CONSTRAINT or not. If you are trying to create a COLUMN level CONSTRAINT, then there seems to be a syntax error in your CONSTRAINT definition (a comma before the word CONSTRAINT).
See the following link from Oracle:
https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj13590.html
It has examples on how to define constraints including COLUMN level constraints. You may want to compare your CONSTRAINT clause with the examples to see if there are errors in your CONSTRAINTS.

Can't create table in Oracle Developer

Hi I am very new to SQL and having a problem for creating the table.
I have been looking at this code for the past two days now and I can not seem to get it to work. It keeps giving me "ORA-00907: missing right parenthesis" I know that this is a topic that comes up a lot but for some reason none of the examples I have seen has helped me. Can someone please tell me why I got this error and how do I fix it. I am pretty sure that it has nothing to do with my parenthesis, maybe its my CONTRAINTS
Here is my Code
create TABLE Employee
(
EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone INT(10) NOT NULL,
JobTitle VARCHAR(10) NOT NULL
);
create TABLE Airplane
(
AirplaneID VARCHAR(10) PRIMARY KEY,
Capacity INT(1000) NOT NULL,
Modle VARCHAR(10) NOT NULL
);
create TABLE Route
(
FlightID VARCHAR(10) PRIMARY KEY,
Origin VARCHAR(20) NOT NULL,
Destination VARCHAR(20) NOT NULL,
ETD INT(10) NOT NULL,
ETA INT(10) NOT NULL
);
create TABLE Customer
(
CustomerID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(10) NOT NULL,
PhoneNumber INT(30) NOT NULL
);
create TABLE Maintenance
(
MaintenanceID VARCHAR(20) PRIMARY KEY,
MaintenanceDate date NOT NULL,
AirplaneID VARCHAR(10) NOT NULL,
EmployeeID VARCHAR(10) NOT NULL,
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
);
create TABLE Flight
(
FlightID VARCHAR(10),
FlightDate date,
AirplaneID VARCHAR(10),
ATD INT(10) NOT NULL,
ATA INT(10) NOT NULL,
FOREIGN KEY (FlightID) REFERENCES Flight(FlightID),
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
CONSTRAINT PK_FlightID PRIMARY KEY (FlightID,FlightDate)
);
create TABLE Reservation
(
ReservationID VARCHAR(20) PRIMARY KEY,
CustomerID VARCHAR(10) NOT NULL,
FlightID VARCHAR(10) NOT NULL,
FlightDate date NOT NULL,
Fare float,
PaymentMethod VARCHAR(20),
CardNumber INT(30) NOT NULL,
ExperationDate date,
check (PaymentMethod = "Cash" OR PaymentMethod ="Credit" OR PaymentMethod
="Cheque",
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
);
create TABLE CrewResveration
(
EmployeeID VARCHAR(10),
FlightID VARCHAR(10),
FlightDate date NOT NULL,
Role VARCHAR(20) NOT NULL,
ShiftHour INT(10) NOT NULL,
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
FORIGNKEY (EmployeeID) REFERENCES Employee(EmployeeID)
CONSTRAINT PK_CrewAssignment PRIMARY (FlightID,FlightDate,EmployeeID)
);
Here are the results I get when I run the code:
Error starting at line : 1 in command -
create TABLE Employee
(
EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone INT(20) NOT NULL,
JobTitle VARCHAR(10) NOT NULL
)
Error at Command Line : 5 Column : 10
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 10 in command -
create TABLE Airplane
(
AirplaneID VARCHAR(10) PRIMARY KEY,
Capacity INT(1000) NOT NULL,
Modle VARCHAR(10) NOT NULL
)
Error at Command Line : 13 Column : 13
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 18 in command -
create TABLE Route
(
FlightID VARCHAR(10) PRIMARY KEY,
Origin VARCHAR(20) NOT NULL,
Destination VARCHAR(20) NOT NULL,
ETD INT(10) NOT NULL,
ETA INT(10) NOT NULL
)
Error at Command Line : 23 Column : 8
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 28 in command -
create TABLE Customer
(
CustomerID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(10) NOT NULL,
PhoneNumber INT(30) NOT NULL
)
Error at Command Line : 32 Column : 16
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 36 in command -
create TABLE Maintenance
(
MaintenanceID VARCHAR(20) PRIMARY KEY,
MaintenanceDate date NOT NULL,
AirplaneID VARCHAR(10) NOT NULL,
EmployeeID VARCHAR(10) NOT NULL,
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
)
Error at Command Line : 42 Column : 37
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error starting at line : 46 in command -
create TABLE Flight
(
FlightID VARCHAR(10),
FlightDate date,
AirplaneID VARCHAR(10),
ATD INT(10) NOT NULL,
ATA INT(10) NOT NULL,
FOREIGN KEY (FlightID) REFERENCES Flight(FlightID),
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
CONSTRAINT PK_FlightID PRIMARY KEY (FlightID,FlightDate)
)
Error at Command Line : 51 Column : 8
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 60 in command -
create TABLE Reservation
(
ReservationID VARCHAR(20) PRIMARY KEY,
CustomerID VARCHAR(10) NOT NULL,
FlightID VARCHAR(10) NOT NULL,
FlightDate date NOT NULL,
Fare float,
PaymentMethod VARCHAR(20),
CardNumber INT(30) NOT NULL,
ExperationDate date,
check (PaymentMethod = "Cash" OR PaymentMethod ="Credit" OR PaymentMethod
="Cheque",
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
)
Error at Command Line : 68 Column : 15
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error starting at line : 76 in command -
create TABLE CrewResveration
(
EmployeeID VARCHAR(10),
FlightID VARCHAR(10),
FlightDate date NOT NULL,
Role VARCHAR(20) NOT NULL,
ShiftHour INT(10) NOT NULL,
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
FORIGNKEY (EmployeeID) REFERENCES Employee(EmployeeID)
CONSTRAINT PK_CrewAssignment PRIMARY (FlightID,FlightDate,EmployeeID)
)
Error at Command Line : 82 Column : 14
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
The error description is misleading, but the pointer (line 5, column 10) points to exactly after reading the word "INT" ... which, is unknown by him. He should state he doesn't understand that, but he mentions something with parenthesis, which ironically are actually correct. Unfortunately, it happens on occasions that error messages are misleading, and you have to think one step further.
The problem is with your data types. INT is not a valid Oracle datatype. Try this instead:
create TABLE Employee ( EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone NUMBER(10) NOT NULL,
JobTitle VARCHAR(10) NOT NULL );

varbinary(max) error in SQL

I want to use a column that contains images in it. I've tried this code
create table books
(
book_id number(4),
title varchar2 (50),
ISBN varchar2(20),
author varchar2(40),
publisher varchar2(20),
released number(4),
image varbinary(max),
constraint booksPK primary key (book_id),
constraint booksFK foreign key (subject_id) references subject(subject_id)
);
and I got this error:
Error at Command Line:29 Column:16
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
please help me with this...
varbinary isn't an Oracle data type. You should be using a binary large object (BLOB). A comment suggested long raw, but BLOBs have fewer restrictions and should be used instead.

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)
);