SQL Error: ORA-00906: missing left parenthesis - oracle

CREATE TABLE Customer_TBL
(CustomerID INTEGER NOT NULL PRIMARY KEY,
CustomerName VARCHAR NOT NULL,
JobPosition VARCHAR,
CompanyName VARCHAR NOT NULL,
USState VARCHAR NOT NULL,
ContactNo BIGINTEGER NOT NULL);
Error starting at line : 1 in command -
Error report - SQL Error: ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:

Biginteger is not supported in Oracle, use number instead. And you need to use varchar2(number of char/bytes) or varchar(number of char/bytes).
Why the error missing left parenthesis?
Because Oracle was expecting ( after VARHCHAR but it was not there.
CREATE TABLE Customer_TBL (CustomerID INTEGER NOT NULL PRIMARY KEY,
CustomerName VARCHAR2(20) NOT NULL,
JobPosition VARCHAR2(20),
CompanyName VARCHAR2(20) NOT NULL,
USState VARCHAR2(20) NOT NULL,
ContactNo NUMBER NOT NULL);

You need to specify a maximum size for VARCHAR fields, e.g: field_name VARCHAR(40),

Related

SQL 00904. 00000 - "%s: invalid identifier" When creating a table

When I create a table like this:
CREATE TABLE "Movie_list" (
"Movie_id" NUMBER(8) NOT NULL,
"Company" VARCHAR2(30) NOT NULL,
"Rating" DECIMAL(5,1) NOT NULL,
"Storyline" VARCHAR2(255) NOT NULL,
"Award_id" VARCHAR2(255) NOT NULL,
"Cast_and_Crew_id" VARCHAR2(255) NOT NULL,
CONSTRAINT Movie_pk PRIMARY KEY (Movie_id),
);
An Error report is producded -
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
I don't see any problem, please help.
Errors:
Table and column names enclosed in quotes
NUMBER and VARCHAR2 are not a valid mysql type
A , is at the end of the constraint specification which is invalid
The main problem is in your primary key specification, which reads
CONSTRAINT Movie_pk PRIMARY KEY (Movie_id),
However, in the table definition you've quoted the name of this field, i.e.
"Movie_id" NUMBER(8) NOT NULL,
Because the name of this field (and in fact every field in the table, and the name of the table itself) is quoted the names are stored by the database as the specified mixed-case name, and because Oracle converts all unquoted identifiers to UPPER_CASE it means that EVERY TIME YOU REFER TO THIS TABLE AND ITS FIELDS, YOU MUST QUOTE THEM. So your constraint should be
CONSTRAINT Movie_pk PRIMARY KEY ("Movie_id")
My recommendation is that you dispense with the quoted "Mixed_case" names. Get rid of the quotes and Oracle will store the names in UPPER_CASE internally. You can still refer to them using Mixed_Case if you want to but you won't have to "Quote_Them_Every_Time_You_Use_Them", which gets really old and reads very badly. I suggest you change you table definition to
CREATE TABLE Movie_list (
Movie_id NUMBER(8) NOT NULL,
Company VARCHAR2(30) NOT NULL,
Rating DECIMAL(5,1) NOT NULL,
Storyline VARCHAR2(255) NOT NULL,
Award_id VARCHAR2(255) NOT NULL,
Cast_and_Crew_id VARCHAR2(255) NOT NULL,
CONSTRAINT Movie_pk PRIMARY KEY (Movie_id)
);
Best of luck.
This also happened to me when I was trying to use some sort of keyword as a column name.
I tried to create a table with a column name of "uid" (without "" evidently), and i was getting this error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
Changing the column's name solved the error.

SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"

i have been trying to make a simple table and i it keeps coming up with SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"
CREATE TABLE USER_TABLE(
USER_ID int NOT NULL,
Username varchar NULL,
Password varchar NULL,
Email varchar NOT NULL,
DOB Date NULL,
Address VARCHAR NOT NULL,
First_name VARCHAR NOT NULL,
Telephone_number int NULL,
PRIMARY KEY (User_ID));
You simply need to add the size of VARCHAR colums:
CREATE TABLE USER_TABLE
(
USER_ID INT NOT NULL,
Username VARCHAR(1) NULL,
Password VARCHAR(1) NULL,
Email VARCHAR(1) NOT NULL,
DOB DATE NULL,
Address VARCHAR(1) NOT NULL,
First_name VARCHAR(1) NOT NULL,
Telephone_number INT NULL,
PRIMARY KEY(User_ID)
);
Notice that VARCHAR is deprecated, better use VARCHAR2

SQL Error: ORA-01722: invalid number

Here is my table.
CREATE TABLE SCHEDULE (
SCHEDULE_ID INT NOT NULL
,ARRV_TIME INT NOT NULL
,DEP_TIME INT NOT NULL
,BUS_TRANSFERS VARCHAR2(40) NOT NULL
,BUS_ID NUMERIC NOT NULL
,TRAVEL_DIRECTION VARCHAR(10) NOT NULL
,WEEK_DAY INTEGER NOT NULL
);
I run this insert statement
INSERT INTO SCHEDULE (SCHEDULE_ID, ARRV_TIME, DEP_TIME, BUS_TRANSFERS, BUS_ID, TRAVEL_DIRECTION, WEEK_DAY)
VALUES (SEQ_SCHEDULE.NEXTVAL,'10', '11', 'White Oak', '2', 'North', '4');
and I get this error message:
Error starting at line : 1 in command - INSERT INTO SCHEDULE
(SCHEDULE_ID, ARRV_TIME, DEP_TIME, BUS_TRANSFERS, BUS_ID,
TRAVEL_DIRECTION, WEEK_DAY) VALUES (SEQ_SCHEDULE.NEXTVAL,'10', '11',
'White Oak', '2', 'North', '4')
Error report - SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
Try This :-
CREATE TABLE SCHEDULE(
SCHEDULE_ID INTEGER NOT NULL ,
ARRV_TIME INTEGER NOT NULL ,
DEP_TIME INTEGER NOT NULL ,
BUS_TRANSFERS VARCHAR2(40) NOT NULL ,
BUS_ID INTEGER NOT NULL ,
TRAVEL_DIRECTION VARCHAR2(10) NOT NULL ,
WEEK_DAY INTEGER NOT NULL );
INSERT INTO SCHEDULE(SCHEDULE_ID, ARRV_TIME, DEP_TIME,BUS_TRANSFERS,BUS_ID, TRAVEL_DIRECTION, WEEK_DAY)
VALUES(SEQ_SCHEDULE.NEXTVAL,10,11, 'White Oak',2,'North',4);
This error is because you have declared arrived_time as int and you are trying to insert '10' value for that. Which is a string please remove the quotes for non string data types

Oracle Unknown Command - CONSTRAINT

I've decided to completely put out the SQL file here.
CREATE TABLE Account
(
AccountNumber INTEGER NOT NULL PRIMARY KEY,
Name varchar(30) NOT NULL
);
CREATE SEQUENCE SEQ_ADDR START WITH 1 INCREMENT BY 1;
CREATE TABLE Address
(
AddressNumber INTEGER NOT NULL PRIMARY KEY,
AccountNumber INTEGER NOT NULL,
IsPrimary INTEGER NOT NULL,
StreetName varchar(50) NOT NULL,
ZipCode INTEGER NOT NULL
);
CREATE TABLE Bill
(
AccountNumber INTEGER NOT NULL,
EndDate DATE NOT NULL,
StartDate DATE NOT NULL,
DueDate DATE NOT NULL,
CONSTRAINT BillFK FOREIGN KEY (AccountNumber) REFERENCES Account(AccountNumber),
CONSTRAINT BillPK PRIMARY KEY (AccountNumber, EndDate)
);
Again, the error I'm getting begins with the first Constraint call (unknown command beginning "CONSTRAINT..." - rest of line ignored.). I'm also occasionally getting an 'unknown command ")" - rest of line ignored.' Any ideas?
Any empty lines will stop SQL*Plus from accepting the inputs blocks and put it in buffer.
So, when you started your CONSTRAINT keyword after an empty line, it treated it as a new command, and thrown an error.
Try this, before you run all your DDLs.
set sqlblanklines on
You need to instruct the sql*plus to ignore empty lines

Oracle Create TABLE

I am trying to create a table with foreign key using oracle. My syntax is as follows
CREATE TABLE product (
product_id INT(7) NOT NULL,
supplier_id INT(7) NOT NULL,
product_name VARCHAR2(30),
product_price DOUBLE(4),
product_category VARCHAR2(30),
product_brand VARCHAR2(20),
product_expire DATE,
PRIMARY KEY (product_id),
FOREIGN KEY (supplier_id)
)
I got a error, saying
Error at Command Line:2 Column:14 Error report: SQL Error: ORA-00907:
missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Please help!
Your foreign key should refference another column on another table.
Here is the documentation you need to fix your issue (how to write the query with the correct syntax for foreign key)
Also, change your data type for column product_price from DOULBE(4) to NUMBER(12,4).
You should not use limit for int type...oracle will take default length for int type .
Instead of int you can use Number type to make it run. And DOUBLE PRECISION is a data type in oracle but Double is not there. Also , syntax for foreign key is wrong.
so this query will work for sure :
CREATE TABLE product(
product_id number(7) NOT NULL,
supplier_id number(7) NOT NULL,
product_name VARCHAR2(30),
product_price DOUBLE PRECISION,
product_category VARCHAR2(30),
product_brand VARCHAR2(20),
product_expire DATE,
PRIMARY KEY (product_id),
FOREIGN KEY (supplier_id)
REFERENCES parent_table (supplier_id)
);
You create like foreign key references parent table that is the proper syntax for creating the foreign key
CREATE TABLE product(
product_id number(7) NOT NULL,
supplier_id number(7) NOT NULL,
product_name VARCHAR(30),
product_price DOUBLE PRECISION,
product_category VARCHAR(30),
product_brand VARCHAR(20),
product_expire DATE,
PRIMARY KEY (product_id),
FOREIGN KEY (supplier_id)
REFERENCES parent_table (supplier_id)
);

Resources