SQL 创建表时出现“ORA-00922:缺少或无效的选项”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9858654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 15:00:04  来源:igfitidea点击:

"ORA-00922: missing or invalid option" when creating tables

sqloracle

提问by sc1013

I entered the following SQL commands in Oracle but it complained "ORA-00922: missing or invalid option"

我在 Oracle 中输入了以下 SQL 命令,但它抱怨“ORA-00922:缺少或无效的选项”

CREATE TABLE Student (
    StuID     NUMBER(15),
    StuName   VARCHAR2(50),
    Phone     VARCHAR2(20),
    PRIMARY KEY (StuID))

CREATE TABLE Program (
    ProCode       VARCHAR2(12),
    ProTitle      VARCHAR2(50),
    PRIMARY KEY (ProCode))

WHY???

为什么???

回答by a_horse_with_no_name

If you are using the dreaded HTML GUI (inside the browser) of OracleXE then that does not support running more than one statement.

如果您使用 OracleXE 可怕的 HTML GUI(在浏览器中),那么它不支持运行多个语句。

Use SQL Developer, SQL*Plus or any other GUI tool instead.

请改用 SQL Developer、SQL*Plus 或任何其他 GUI 工具。

回答by egrunin

CREATE TABLE Student (
    StuID     NUMBER(15),
    StuName   VARCHAR2(50),
    Phone     VARCHAR2(20),
    CONSTRAINT PK_STUID PRIMARY KEY (StuID))

Found the answer here.

这里找到了答案。

Edit:

编辑:

Also, try using /as a statement separator, instead of a ;

此外,尝试使用/作为语句分隔符,而不是;

回答by Dor Cohen

Try no to define the size of StuID. also add constraint key work and just to make sure use DROP before CREATE like this:

尝试 no 来定义 StuID 的大小。还添加约束键工作,并确保在 CREATE 之前使用 DROP,如下所示:

DROP TABLE Student;

CREATE TABLE Student (
    StuID     NUMBER,
    StuName   VARCHAR2(50),
    Phone     VARCHAR2(20),
    constraint pk_Student PRIMARY KEY (StuID));

DROP TABLE Program;

CREATE TABLE Program (
    ProCode       VARCHAR2(12),
    ProTitle      VARCHAR2(50),
    constraint pk_Program PRIMARY KEY (ProCode));