Hello, I'm trying to create tables in oracle sqlplus, but I keep getting an invalid datatype error

huangapple go评论138阅读模式
英文:

Hello, I'm trying to create tables in oracle sqlplus, but I keep getting an invalid datatype error

问题

SQL> 创建表 PlaysplayId INT 主键,gameId INTplayNumber INTquarter INTtime TIMESTAMPyardLine INTpossessionTeam VARCHAR210),playType VARCHAR210),yardGain INTyardsToGo INTdown INTdistance INTyardsToEndzone INTscoreDiff INTepa REALisRush BOOLEANisPass BOOLEANisIncomplete BOOLEANisTouchdown BOOLEANpassType VARCHAR210),passLocation VARCHAR210),rushDirection VARCHAR210),rushLocation VARCHAR210),receiver VARCHAR220),defender VARCHAR220));

> 创建表 PlaysplayId INT 主键,gameId INTplayNumber INTquarter INTtime TIMESTAMPyardLine INTpossessionTeam VARCHAR210),playType VARCHAR210),yardGain INTyardsToGo INTdown INTdistance INTyardsToEndzone INTscoreDiff INTepa REALisRush BOOLEANisPass BOOLEANisIncomplete BOOLEANisTouchdown BOOLEANpassType VARCHAR210),passLocation VARCHAR210),rushDirection VARCHAR210),rushLocation VARCHAR210),receiver VARCHAR220),defender VARCHAR220));
>                                                                                                                                                                                                                                                                                                                                                                                                  *
> 
> 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)
);

fiddle

英文:

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 &#39;Y&#39;/&#39;N&#39; 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 (&#39;Y&#39;, &#39;N&#39;)),
    isPass         CHAR(1) CHECK (isPass IN (&#39;Y&#39;, &#39;N&#39;)),
    isIncomplete   CHAR(1) CHECK (isIncomplete IN (&#39;Y&#39;, &#39;N&#39;)),
    isTouchdown    CHAR(1) CHECK (isTouchdown IN (&#39;Y&#39;, &#39;N&#39;)),
    passType       VARCHAR2(10),
    passLocation   VARCHAR2(10),
    rushDirection  VARCHAR2(10),
    rushLocation   VARCHAR2(10),
    receiver       VARCHAR2(20),
    defender       VARCHAR2(20)
);

fiddle

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

huangapple
  • 本文由 发表于 2023年3月9日 16:56:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定