英文:
Hello, I'm trying to create tables in oracle sqlplus, but I keep getting an invalid datatype error
问题
SQL> 创建表 Plays(playId INT 主键,gameId INT,playNumber INT,quarter INT,time TIMESTAMP,yardLine INT,possessionTeam VARCHAR2(10),playType VARCHAR2(10),yardGain INT,yardsToGo INT,down INT,distance INT,yardsToEndzone INT,scoreDiff INT,epa REAL,isRush BOOLEAN,isPass BOOLEAN,isIncomplete BOOLEAN,isTouchdown BOOLEAN,passType VARCHAR2(10),passLocation VARCHAR2(10),rushDirection VARCHAR2(10),rushLocation VARCHAR2(10),receiver VARCHAR2(20),defender VARCHAR2(20));
> 创建表 Plays(playId INT 主键,gameId INT,playNumber INT,quarter INT,time TIMESTAMP,yardLine INT,possessionTeam VARCHAR2(10),playType VARCHAR2(10),yardGain INT,yardsToGo INT,down INT,distance INT,yardsToEndzone INT,scoreDiff INT,epa REAL,isRush BOOLEAN,isPass BOOLEAN,isIncomplete BOOLEAN,isTouchdown BOOLEAN,passType VARCHAR2(10),passLocation VARCHAR2(10),rushDirection VARCHAR2(10),rushLocation VARCHAR2(10),receiver VARCHAR2(20),defender VARCHAR2(20));
> *
>
> 第1行出错:<BR> ORA-00902:无效的数据类型
尝试创建 SQL 表时遇到无效的数据类型错误,但从我的端来看,一切似乎都没问题。
英文:
SQL> CREATE TABLE Plays ( playId INT PRIMARY KEY, gameId INT, playNumber INT, quarter INT, time TIMESTAMP, yardLine INT, possessionTeam VARCHAR2(10), playType VARCHAR2(10), yardGain INT, yardsToGo INT, down INT, distance INT, yardsToEndzone INT, scoreDiff INT, epa REAL, isRush BOOLEAN, isPass BOOLEAN, isIncomplete BOOLEAN, isTouchdown BOOLEAN, passType VARCHAR2(10), passLocation VARCHAR2(10), rushDirection VARCHAR2(10), rushLocation VARCHAR2(10), receiver VARCHAR2(20), defender VARCHAR2(20));
> CREATE TABLE Plays ( playId INT PRIMARY KEY, gameId INT,
> playNumber INT, quarter INT, time TIMESTAMP, yardLine INT,
> possessionTeam VARCHAR2(10), playType VARCHAR2(10), yardGain
> INT, yardsToGo INT, down INT, distance INT, yardsToEndzone
> INT, scoreDiff INT, epa REAL, isRush BOOLEAN, isPass
> BOOLEAN, isIncomplete BOOLEAN, isTouchdown BOOLEAN,
> passType VARCHAR2(10), passLocation VARCHAR2(10), rushDirection
> VARCHAR2(10), rushLocation VARCHAR2(10), receiver VARCHAR2(20),
> defender VARCHAR2(20))
> *
>
> ERROR at line 1:<BR> ORA-00902: invalid datatype
Tried to create sql table but got an invalid datatype error but from my side everything seems fine
答案1
得分: 1
BOOLEAN
不是有效的 Oracle SQL 数据类型(在 PL/SQL 中是有效的)。
你可以使用不同的数据类型,比如 CHAR(1)
或者 NUMBER(1,0)
,并添加检查约束来限制它为 'Y'
/'N'
或者 1
/0
。
CREATE TABLE Plays (
playId INT PRIMARY KEY,
gameId INT,
playNumber INT,
quarter INT,
time TIMESTAMP,
yardLine INT,
possessionTeam VARCHAR2(10),
playType VARCHAR2(10),
yardGain INT,
yardsToGo INT,
down INT,
distance INT,
yardsToEndzone INT,
scoreDiff INT,
epa REAL,
isRush CHAR(1) CHECK (isRush IN ('Y', 'N')),
isPass CHAR(1) CHECK (isPass IN ('Y', 'N')),
isIncomplete CHAR(1) CHECK (isIncomplete IN ('Y', 'N')),
isTouchdown CHAR(1) CHECK (isTouchdown IN ('Y', 'N')),
passType VARCHAR2(10),
passLocation VARCHAR2(10),
rushDirection VARCHAR2(10),
rushLocation VARCHAR2(10),
receiver VARCHAR2(20),
defender VARCHAR2(20)
);
英文:
BOOLEAN
is not a valid Oracle SQL data-type. (It is a valid data-type in PL/SQL.)
You can use a different data-type such as CHAR(1)
or NUMBER(1,0)
and add check constraints to restrict it to 'Y'
/'N'
or 1
/0
.
CREATE TABLE Plays (
playId INT PRIMARY KEY,
gameId INT,
playNumber INT,
quarter INT,
time TIMESTAMP,
yardLine INT,
possessionTeam VARCHAR2(10),
playType VARCHAR2(10),
yardGain INT,
yardsToGo INT,
down INT,
distance INT,
yardsToEndzone INT,
scoreDiff INT,
epa REAL,
isRush CHAR(1) CHECK (isRush IN ('Y', 'N')),
isPass CHAR(1) CHECK (isPass IN ('Y', 'N')),
isIncomplete CHAR(1) CHECK (isIncomplete IN ('Y', 'N')),
isTouchdown CHAR(1) CHECK (isTouchdown IN ('Y', 'N')),
passType VARCHAR2(10),
passLocation VARCHAR2(10),
rushDirection VARCHAR2(10),
rushLocation VARCHAR2(10),
receiver VARCHAR2(20),
defender VARCHAR2(20)
);
答案2
得分: 0
在Oracle中,您不能使用BOOLEAN数据类型。
一个有效的创建语句如下:
CREATE TABLE Plays
(playId INT PRIMARY KEY,
gameId INT,
playNumber INT,
quarter INT,
time TIMESTAMP,
yardLine INT,
possessionTeam VARCHAR2(10),
playType VARCHAR2(10),
yardGain INT,
yardsToGo INT,
down INT,
distance INT,
yardsToEndzone INT,
scoreDiff INT,
epa REAL,
isRush char(1),
isPass char(1),
isIncomplete char(1),
isTouchdown char(1),
passType VARCHAR2(10),
passLocation VARCHAR2(10),
rushDirection VARCHAR2(10),
rushLocation VARCHAR2(10),
receiver VARCHAR2(20),
defender VARCHAR2(20));
英文:
In Oracle you cannot use BOOLEAN datatype.
A valid create statement is the following:
CREATE TABLE Plays
(playId INT PRIMARY KEY,
gameId INT,
playNumber INT,
quarter INT,
time TIMESTAMP,
yardLine INT,
possessionTeam VARCHAR2(10),
playType VARCHAR2(10),
yardGain INT,
yardsToGo INT,
down INT,
distance INT,
yardsToEndzone INT,
scoreDiff INT,
epa REAL,
isRush char(1),
isPass char(1),
isIncomplete char(1),
isTouchdown char(1),
passType VARCHAR2(10),
passLocation VARCHAR2(10),
rushDirection VARCHAR2(10),
rushLocation VARCHAR2(10),
receiver VARCHAR2(20),
defender VARCHAR2(20));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论