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

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,

Related

ORA-00907: missing right parenthesis .. when i don't have any missing parenthesis or spelling mistakes [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
When I run this SQL it gives me this error and I can't figure it out
CREATE TABLE PAYMENT (
Payment_ID int(16) not null,
Amount_paid varchar2(30) not null,
Payment_ReceivedBy varchar(30) not null,
Payment_ReceivedFrom varchar(30) not null,
Payment_Date datetime not null,
Card_Number varchar2(20) not null,
Card_Holder_Name varchar2(30) not null,
Is_CreditCard number(20) ,
Is_DebitCard number(20),
Online_Payment varchar(10),
CashOnDelivery varchar(10),
CONSTRAINT PaymentID_PK PRIMARY KEY (Payment_ID)
);
error:
ORA-00907: missing right parenthesis
The error message isn't great, and the issue in fact isn't really about parenthesis - it's about datatypes. Oracle doesn't have int and datetime types. Instead, you could use number(16) and date:
CREATE TABLE PAYMENT (
Payment_ID number(16) not null, -- Here
Amount_paid varchar2(30) not null,
Payment_ReceivedBy varchar(30) not null,
Payment_ReceivedFrom varchar(30) not null,
Payment_Date date not null, -- And here
Card_Number varchar2(20) not null,
Card_Holder_Name varchar2(30) not null,
Is_CreditCard number(20) ,
Is_DebitCard number(20),
Online_Payment varchar(10),
CashOnDelivery varchar(10),
CONSTRAINT PaymentID_PK PRIMARY KEY (Payment_ID)
);

Getting an error that I'm missing a right paren when I am not [duplicate]

This question already has answers here:
Missing right Paranthesis on Create Table command SQL
(2 answers)
Closed 3 years ago.
I'm getting an error when creating two tables that I'm missing a right paren on the second table although I am not.
I've tried different oracle variations of this code and I'm still getting the error.
(ORACLE LIVE SQL)
CREATE TABLE PET_OWNER
(OwnerID Integer Primary Key,
OwnerLastName Char(25) Not Null,
OwnerFirstName Char(25) Not Null,
OwnerPhone Char(25) Null,
OwnerEmail Char(50) Not Null);
CREATE TABLE PET_DATA
(PetID Integer Not Null,
PetName Char(50) Not Null,
PetType Char(25) Not Null,
PetBreed Char(50) Not Null,
PetDOB Varchar(50) Not Null,
Primary Key (PetID)
Constraint FK_PetOwner Foreign Key (OwnerID)
References Owner(OwnerID));
I expect the tables to be created but only the first table is being created successfully. The second table has a foreign key.
It looks like you are missing a comma after the primary-key definition on the second table.
The Oracle parser often complains about missing closing parentheses when the real issue is some other syntax error.
I would recommend:
CREATE TABLE PET_OWNER (
OwnerID Integer Primary Key,
OwnerLastName varchar2(25) Not Null,
OwnerFirstName varchar2(25) Not Null,
OwnerPhone varchar2(25) Null,
OwnerEmail varchar2(50) Not Null
);
CREATE TABLE PET_DATA (
PetID Integer Not Null,
OwnerID Integer,
PetName varchar2(50) Not Null,
PetType varchar2(25) Not Null,
PetBreed varchar2(50) Not Null,
PetDOB varchar2(50) Not Null,
Primary Key (PetID),
Constraint FK_PetOwner Foreign Key (OwnerID) References Pet_Owner(OwnerID)
);
This fixes small problems (missing OwnerId column in the second table, wrong table name). It also uses varchar2() for variable length strings rather than char() -- which are padded with spaces to the specified length.

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

Missing Right parenthesis error?

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.

SQL Create table missing parenthesis [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am running these two commands to create new tables, but the second create table command keeps giving me error.
CREATE TABLE TEAMSTADIUM(
stadium_name varchar2(40) not null,
stadium_max_capcity number(10) not null,
stadium_field_serface varchar2(40) not null,
stadium_year_built number(4) not null,
stadium_location varchar2(40) not null,
Primary KEY(stadium_name)
)
CREATE TABLE TEAMINFO(
team_name varchar2(40) not null,
team_owner varchar2(40) not null,
team_coach varchar2(40) not null,
team_created Date() not null,
PRIMARY KEY(team_name)
foreign key(stadium_name) references TEAMSTADIUM(stadium_name)
)
Your TEAMINFO table references TEAMSTADIUM.stadium_name, but has no such column of its own. Add it, and ensure it has exactly the same data type as the parent table:
CREATE TABLE TEAMINFO(
team_name varchar2(40) not null,
team_owner varchar2(40) not null,
team_coach varchar2(40) not null,
team_created Date not null,
-- Remove () ^^
-- This column must exist in both tables
stadium_name varchar2(40) not null,
PRIMARY KEY(team_name),
-- missing comma ^^
foreign key(stadium_name) references TEAMSTADIUM(stadium_name)
)
After applying the three modifications above, it will execute correctly: http://sqlfiddle.com/#!4/883a4
Try using Date not null; and put ; after each ) of end table
CREATE TABLE TEAMINFO(
stadium_name varchar2(40) not null,
team_name varchar2(40) not null,
team_owner varchar2(40) not null,
team_coach varchar2(40) not null,
team_created Date not null,
PRIMARY KEY(team_name),
foreign key(stadium_name) references TEAMSTADIUM(stadium_name)
);