Missing Right parenthesis error? - sql

I'm trying to create a table in sqldeveloper however I keep getting a missing right parenthesis error when there are no missing right parenthises. Any fixes for this or am i just trying to create a table the wrong way?
CREATE TABLE Patient_T1(
PATIENT_ID INT(100) NOT NULL,
FIRST_NAME VARCHAR(20) NOT NULL,
LAST_NAME VARCHAR(30) NOT NULL,
DOB CHAR(10) NOT NULL,
P_STREET_ADRESS VARCHAR(50) NOT NULL,
PATIENT_CITY VARCHAR(30) NOT NULL,
PATIENT_STATE CHAR(2) NOT NULL,
PATIENT_ZIP CHAR(5) NOT NULL,
PATIENT_PHONE CHAR(12) NOT NULL,
PATIENT_ROOM INT(1000) NOT NULL,
CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENT_ID));

Not sure why Oracle gives that error message instead of something more helpful, but the cause is the precision applied to INT, switch from INT(100) and INT(1000) to just INT:
CREATE TABLE Patient_T1(
PATIENT_ID INT NOT NULL,
FIRST_NAME VARCHAR(20) NOT NULL,
LAST_NAME VARCHAR(30) NOT NULL,
DOB CHAR(10) NOT NULL,
P_STREET_ADRESS VARCHAR(50) NOT NULL,
PATIENT_CITY VARCHAR(30) NOT NULL,
PATIENT_STATE CHAR(2) NOT NULL,
PATIENT_ZIP CHAR(5) NOT NULL,
PATIENT_PHONE CHAR(12) NOT NULL,
PATIENT_ROOM INT NOT NULL,
CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENT_ID));

There are multiple issues with your table DDL:
INT(100) - In Oracle, an INTEGER is an ANSI SQL data type which refers to numeric values which have only an integer portion and no floating point or decimal part. That is, an INTEGER will only store whole numbers ONLY.
VARCHAR(20) - Oracle strongly recommends to use VARCHAR2.
From documentation,
VARCHAR Datatype
The VARCHAR datatype is synonymous with the VARCHAR2 datatype. To
avoid possible changes in behavior, always use the VARCHAR2 datatype
to store variable-length character strings.
CHAR(10) - better use VARCHAR2 as CHAR is blank-padded to the fixed length. That's a wastage of storage.
From documentation,
CHAR Datatype
The CHAR datatype stores fixed-length character strings. If you give a
shorter value, then the value is blank-padded to the fixed length.
Only the issue# 1 would throw an error, anyway fixing all the above issues would let you create the table.
For example,
SQL> CREATE TABLE Patient_T1
2 (
3 PATIENT_ID NUMBER NOT NULL,
4 FIRST_NAME VARCHAR2(20) NOT NULL,
5 LAST_NAME VARCHAR2(30) NOT NULL,
6 DOB DATE NOT NULL,
7 P_STREET_ADRESS VARCHAR2(50) NOT NULL,
8 PATIENT_CITY VARCHAR2(30) NOT NULL,
9 PATIENT_STATE VARCHAR2(2) NOT NULL,
10 PATIENT_ZIP VARCHAR2(5) NOT NULL,
11 PATIENT_PHONE VARCHAR2(12) NOT NULL,
12 PATIENT_ROOM NUMBER NOT NULL,
13 CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENT_ID)
14 );
Table created.

Related

00905. 00000 - "missing keyword"

I'm new to SQL and I'm stuck with creating the table
CREATE TABLE Recording(
recordingID int not null,
title varchar(255) not null,
nameRec varchar(255) not null,
price DOUBLE not null,
quantityStock int not null,
musicID int not null,
StockDiscNum int not null,
orderNums int not null,
FOREIGN KEY(orderNums) REFERENCES Orders (orderNumber),
PRIMARY KEY(recordingID)
);
I checked every type but not sure why it say missing keyword
Thank you
What is the exact issue and the exact way to create table in SQL
There's no DOUBLE datatype in Oracle; use NUMBER instead. Also, Oracle recommends us to use varchar2 instead of varchar.
SQL> CREATE TABLE Recording
2 (
3 recordingID INT NOT NULL,
4 title VARCHAR2 (255) NOT NULL,
5 nameRec VARCHAR2 (255) NOT NULL,
6 price NUMBER NOT NULL,
7 quantityStock INT NOT NULL,
8 musicID INT NOT NULL,
9 StockDiscNum INT NOT NULL,
10 orderNums INT NOT NULL,
11 FOREIGN KEY (orderNums) REFERENCES Orders (orderNumber),
12 PRIMARY KEY (recordingID)
13 );
Table created.
SQL>

ORA-00907 (missing right parenthesis)

I'm trying to run this in my database but for some reason, I keep getting missing the right parenthesis. Thoughts?
CREATE TABLE PET_OWNER
(
OwnerID Int NOT NULL IDENTITY(1, 1),
OwnerLastName Char(25) NOT NULL,
OwnerFirstName Char(25) NOT NULL,
OwnerPhone Char(12) NULL,
OwnerEmail VarChar(100) NULL
CONSTRAINT OWNER_PK PRIMARY KEY(OwnerID)
);
EShirvana's answer directly answers the question you asked. However, I would suggest:
CREATE TABLE PET_OWNER (
OwnerID Int generated always as identity primary key,
OwnerLastName varchar2(25) NOT NULL,
OwnerFirstName varchar2(25) NOT NULL,
OwnerPhone varchar2(12),
OwnerEmail varchar2(100)
);
The differences:
The primary key constraint can be inlined. To be honest, I don't generally see much use for naming the primary key as a separate constraint (no harm).
Declaring a primary key column as NOT NULL is redundant. That is part of being a primary key.
Do you know what the char() data type does? It pads strings with spaces so they match the length. Use variable length strings -- and Oracle recommends varchar2() for this purpose.
By default, columns are NULLable. I actually find that explicitly declaring NULL is harder to read because I have to distinguish between NOT NULL and NULL which requires more work than just seeing NOT NULL.
2 issues:
identity and missing comma before constraint:
CREATE TABLE PET_OWNER(
OwnerID Int GENERATED ALWAYS AS IDENTITY NOT NULL,
OwnerLastName Char(25) NOT NULL,
OwnerFirstName Char(25) NOT NULL,
OwnerPhone Char(12) NULL,
OwnerEmail VarChar(100) NULL,
CONSTRAINT OWNER_PK PRIMARY KEY(OwnerID)
);

what does the error "missing right parenthesis" in oracle sql means

I'm trying to run this code and it seems correct to me but I'm getting an error stating that there's a right parenthesis missing.
The code is the following:
CREATE TABLE CUSTOMER
(
CUSTOMER_ID INT NOT NULL,
NAME VARCHAR(30) NOT NULL,
DATE_OF_BIRTH DATE,
PHONE_NB CHAR(8) NOT NULL,
ADDRESS VARCHAR(50),
TOTAL_SPENDING FLOAT NOT NULL DEFAULT 0.0,
PRIMARY KEY(CUSTOMER_ID)
);
Can anyone help me in solving my problem?
Since you tagged SQL Developer...
...the tool tries to give you a heads-up there will be a problem before you even hit the Execute button
The default value for the column is confusing the parser because it's not expected at that point.
Move it to after the data type and you'll be good
CREATE TABLE customer (
customer_id INT NOT NULL,
name VARCHAR2(30) NOT NULL,
date_of_birth DATE,
phone_nb CHAR(8) NOT NULL,
address VARCHAR(50),
total_spending FLOAT DEFAULT 0.0 NOT NULL,
PRIMARY KEY ( customer_id )
);
PS In oracle, use VARCHAR2, not VARCHAR. While VARCHAR will 'work', it's reserved and could mean something different in a future release.
You are using wrong order of column definition clauses: the constraint (NOT NULL) should follow the default value.
This is the right way:
CREATE TABLE CUSTOMER
(
CUSTOMER_ID INT NOT NULL,
NAME VARCHAR(30) NOT NULL,
DATE_OF_BIRTH DATE,
PHONE_NB CHAR(8) NOT NULL,
ADDRESS VARCHAR(50),
TOTAL_SPENDING FLOAT DEFAULT 0.0 NOT NULL ,
PRIMARY KEY(CUSTOMER_ID)
);

ORA-00902: invalid datatype trying to define a column with a unique constraint [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I created the following table definition in netbeans ide 8.
CREATE TABLE DOCTOR_INFO(
DOCTOR_ID NUMBER(38) NOT NULL CONSTRAINT DOCTORINFO_ID_UQ UNIQUE,
D_F_NAME VARCHAR(50) NOT NULL,
D_M_NAME VARCHAR(50) NOT NULL,
D_S_NAME VARCHAR(50) NOT NULL,
DOCTOR_NAME VARCHAR(50),
D_TITLE VARCHAR(10) NOT NULL,
D_ACTIVE_STATUS BOOLEAN NOT NULL,
SUFFIX VARCHAR(10) NOT NULL,
PASSWORD VARCHAR(50) NOT NULL,
SPECIALITY VARCHAR(35) NOT NULL,
QUALIFICATION_YEAR NUMBER(4) NOT NULL,
UNIVERSITY_NAME VARCHAR(35) NOT NULL,
HOSPITAL_NAME VARCHAR(35) NOT NULL,
D_ADDR1 VARCHAR(50),
D_ADDR2 VARCHAR(50),
USER_EMAIL_ADDRESS VARCHAR(255) NOT NULL,
D_CITY VARCHAR(50) NOT NULL,
D_STATE VARCHAR(50),
D_ZIPCODE NUMBER(6) NOT NULL,
D_HOMEPHONE NUMBER(15) NOT NULL,
D_WORKPHONE NUMBER(15) NOT NULL,
D_MOBILE NUMBER(15) NOT NULL,
START_DAYTIME TIMESTAMP,
END_DAYTIME TIMESTAMP,
START_NIGHTTIME TIMESTAMP,
END_NIGHTTIME TIMESTAMP,
D_TOKENLIMIT NUMBER(4),
D_DOB DATE NOT NULL
);
When I try to run it in Oracle 10g, I get this error:
Error code 902, SQL state 42000: ORA-00902: invalid datatype
Line 1, column 1
What is wrong with the table definition?
Your definition for column DOCTOR_ID does not conform to Oracle SQL syntax. You cannot append a named constraint to a column declaration as you attempt to do. You may do this ...
DOCTOR_ID NUMBER(38) NOT NULL,
CONSTRAINT DOCTORINFO_ID_UQ UNIQUE (DOCTOR_ID),
... to achieve the effect you seem to want. If you don't care about the specific constraint name, however, then you can also do this:
DOCTOR_ID NUMBER(38) NOT NULL UNIQUE,

Oracle error sql

I have to create a table and insert values into the tables. The tables is being created but it wont insert values.
heres my code-
CREATE TABLE CUSTOMER(
CID number(20) not null primary key,
FNAME varchar2(50) not null,
MIDDLE varchar2(50) null,
LNAME varchar2(50) not null,
STREET varchar2(50) not null,
CITY varchar2(50) not null,
STATE char(2) not null,
ZIP varchar2(5) not null,
PHONE varchar2(20) not null,
BIRTH_YR date);
INSERT INTO CUSTOMER VALUES(
'1','john','paul','connor','Broad st','newark','nj','07103','2018643110','1992');
I keep getting an error
[Error] Script lines: 12-14 ------------------------
ORA-01861: literal does not match format string
Script line 14, statement line 2, column 85
Can somebody help me out? What am i doing wrong?
You must change the table definition to something like below to allow insertion of year in the format you need:
CREATE TABLE CUSTOMER(
CID number(20) not null primary key,
FNAME varchar2(50) not null,
MIDDLE varchar2(50) null,
LNAME varchar2(50) not null,
STREET varchar2(50) not null,
CITY varchar2(50) not null,
STATE char(2) not null,
ZIP varchar2(5) not null,
PHONE varchar2(20) not null,
BIRTH_YR char(4) not null);
Otherwise, you have to provide literal date values in the default format accepted by your Oracle database. You can use this query to find out what is the date format accepted by your system:
SELECT *
FROM nls_database_parameters
WHERE parameter LIKE '%DATE%'
For me, it returns:
NLS_DATE_FORMAT | DD-MON-RR
---------------------------------
NLS_DATE_LANGUAGE | AMERICAN
which means instead of '1992', I should insert values such as '01-Jan-1992' in the BIRTH_YR column:
INSERT INTO CUSTOMER
VALUES('1','john','paul','connor','Broad st','newark','nj','07103','2018643110', '01-Jan-1992');
BIRTH_YR being a DATE field should be given in 'yyyy-MM-dd' format, '1992-01-01'.