ORACLE SQL - invalid data type on table creation - sql

I am trying to set up a table in an ORACLE database and am getting an invalid data type error when I try to run this command:
CREATE TABLE Students (
StudentID NUMBER(8) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
Surname VARCHAR(25) NOT NULL,
Address VARCHAR(100) NOT NULL,
Postcode VARCHAR(7) NOT NULL,
DoB DATE NOT NULL,
Gender VARCHAR(1) NOT NULL,
StudentCategory VARCHAR(50),
StudyType VARCHAR(20),
Nationality VARCHAR(20),
SmokerStatus BOOLEAN,
SpecialNeeds VARCHAR(30),
Comments VARCHAR(30),
PlacedStatus BOOLEAN,
CourseID NUMBER(6) NOT NULL,
AdvisorOfStudies NUMBER(6) NOT NULL,
NextOfKin NUMBER(8) NOT NULL
);
According to the error message, something is occuring 'starting on line 1'. That would mean on the actual create statement itself, rather than any of the data dictionary. I don't understand how this can be causing the invalid data type error.
If anyone can spot what might be causing this, that'd be greatly appreciated!
Error Details:
Error report -
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Thanks,
Mark

Change SmokerStatus from BOOLEAN to char(1). Oracle does not have boolean data type . You need to use char(1) or number(1) for this purpose.
SmokerStatus char(1),

Related

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

SQL- Invalid identifier when creating foreign key- SQL Error: ORA-00904

Whenever I run the script I keep getting this error:
Error report - SQL Error: ORA-00904: "HORSE_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I am trying to make a foreign key linking the HORSES and MEDICAL table. I think everything looks correct. Can someone let me know what I have done incorrectly? I am using Oracle SQLDeveloper.
CREATE TABLE HORSES (
Horse_ID varchar(10) NOT NULL Primary Key,
Name varchar(50) NOT NULL,
Height varchar(50) NOT NULL,
Weight varchar(50) NOT NULL,
Breed varchar(50) NOT NULL,
Surrender varchar(50) NOT NULL,
Seize varchar(50) NOT NULL,
Score varchar(15) NOT NULL,
Aq_Date varchar(10) NOT NULL,
Ridable varchar(50) NOT NULL,
Trim varchar(50) NOT NULL,
Age varchar(50) NOT NULL
);
/* MEDICAL */
/* ------------------------------------------------------------ */
CREATE TABLE MEDICAL (
Med_ID varchar(50) NOT NULL primary key,
Feed_Ins varchar(4000) NOT NULL,
Special_Vet varchar(2000) NOT NULL,
Coggins varchar(50) NOT NULL,
Vaccs varchar(50) NOT NULL,
Deworm varchar(50) NOT NULL,
CONSTRAINT Horse_ID_HORSES_FK FOREIGN KEY (Horse_ID) REFERENCES HORSES(Horse_ID)
);
You don't have a horse_id column in medical, how do you want it to be fk for that table?

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,

Sql syntax error - expecting ( or as

I am trying to write this SQL code:
create table Users
{
UserID int primary key identity(200,1),
FirstName varchar(20) not null,
LastName varchar(20) not null,
BirthDate dateTime not null,
HomeTown varchar(30),
WorkPlace varchar(40),
Email not null
}
The problem is that next the { symbol, I get the error:
Incorrect syntax near '{'.
When my mouse over the sign it adds:
Expecting '(' or AS
In addition, I also get an error on the values that are in the bracket
Incorrect syntax near '20'. Expecting '(' or Select".
The thing is that I have another SQL document (that I didn't write) and the same syntax work there! Why is that and how can I solve it?
You need brackets not braces - http://www.w3schools.com/sql/sql_create_table.asp Also a data type for email
I.e.
create table Users
(
UserID int primary key identity(200,1),
FirstName varchar(20) not null,
LastName varchar(20) not null,
BirthDate dateTime not null,
HomeTown varchar(30),
WorkPlace varchar(40),
Email varchar(40) not null
)
You have not specified the datatype for Email columnn.
Use ()instead of {}.
Your sql statement should look like the following one, first change the {} to () then added the datatype to your email column
create table Users (
UserID int primary key identity(200,1),
FirstName varchar(20) not null,
LastName varchar(20) not null,
BirthDate dateTime not null,
HomeTown varchar(30),
WorkPlace varchar(40),
[Email] varchar(255) not null
)

There was an error parsing the query. [ Token line number = 2,Token line offset = 3,Token in error = Employee_ID ]

I am trying to execute the below query but iam getting the folowing error.
Create table Employee(
Employee_ID char(5)Primary key,
First_Name char(20) NOT NULL,
Last_Name char(20) NOT NULL,
Phone_Number varchar(20) NULL
);
Major Error 0x80040E14, Minor Error 26302
> Create table Employee(
Employee_ID char(5)Primary key,
First_Name char(20) NOT NULL,
Last_Name char(20) NOT NULL,
Phone_Number varchar(20) NULL
)
The specified data type is not valid. [ Data type (if known) = char ]
If the database you are using is some version of Microsoft SQL Server Compact Edition (which the error message would suggest) the error stems from the fact that particular database doesn't support thechar/varchardata types as it's purely unicode based. What you need to do is to use the corresponding unicode data typesnchar/nvarcharlike this:
Create table Employee (
Employee_ID nchar(5) Primary key,
First_Name nchar(20) NOT NULL,
Last_Name nchar(20) NOT NULL,
Phone_Number nvarchar(20) NULL
);
For reference: Data Types Supported in SQL Server CE