Percy Shey
Percy Shey

Reputation: 27

Invalid identifier error but i can't see why

Started learning SQL and am having a go at creating a script. The code looks perfectly fine to me but I keep getting the invalid identifier error. I've checked the code over and over again but everything seems ok. I'm going mad here. I am using oracle by the way.

create table Products ( ID int not null, Item varchar(30) not null, Size 
varchar(1) not null);
insert into Products values ( 321, 'T-shirt', 'M');
insert into Products values ( 211, 'Jeans', 'L');

Upvotes: 1

Views: 1024

Answers (2)

Mureinik
Mureinik

Reputation: 311338

size is a reserved word in Oracle's SQL (not sure if it is according to the ANSI standard, but some databases, like MySQL, definitely allow it).

You could escape it by using double quotes ("):

CREATE TABLE Products (
    ID INT NOT NULL,
    Item VARCHAR(30) NOT NULL,
    "Size" VARCHAR(1) NOT NULL
);

But it would be much easier to just choose a name that isn't a reserved word:

CREATE TABLE Products (
    ID INT NOT NULL,
    Item VARCHAR(30) NOT NULL,
    ProductSize VARCHAR(1) NOT NULL
);

Upvotes: 1

Aaron Dietz
Aaron Dietz

Reputation: 10277

Size is a reserved word in Oracle, try changing the column name to an unreserved word.

See here for the full list of reserved words

Upvotes: 2

Related Questions