标识符错误无效但我看不清楚原因

时间:2022-11-22 22:45:38

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.

开始学习SQL并开始创建脚本。代码看起来很好,但我一直得到无效的标识符错误。我一遍又一遍地检查了代码,但一切似乎都没问题。我在这里生气。我顺便使用oracle。

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

2 个解决方案

#1


1  

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

size是Oracle SQL中的保留字(不确定它是否符合ANSI标准,但某些数据库,如MySQL,绝对允许它)。

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

#2


2  

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

大小是Oracle中的保留字,请尝试将列名更改为无保留字。

See here for the full list of reserved words

请参阅此处以获取保留字的完整列表

#1


1  

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

size是Oracle SQL中的保留字(不确定它是否符合ANSI标准,但某些数据库,如MySQL,绝对允许它)。

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

#2


2  

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

大小是Oracle中的保留字,请尝试将列名更改为无保留字。

See here for the full list of reserved words

请参阅此处以获取保留字的完整列表