简体   繁体   English

ORA-00922: 无法使用 ojdbc 在 oracle 中创建表

[英]ORA-00922 : Cannot Create table in oracle using ojdbc

I want to create the following table我想创建下表

CREATE TABLE EMPLOYEE (
    name_id varchar(255) PRIMARY KEY,
    modified_at TIMESTAMP,
    created_at TIMESTAMP
);

but oracle give the error但 oracle 给出错误

ORA-00922: missing or invalid option ORA-00922: 缺少或无效选项

I also tried the following SQL request but same issue is happening我也尝试了以下 SQL 请求,但同样的问题正在发生

CREATE TABLE EMPLOYEE (
    name_id varchar(255),
    modified_at TIMESTAMP,
    created_at TIMESTAMP,
    CONSTRAINT EMPLOYEE UNIQUE (name_id)
);

The request where executed using java code and the driver ojdbc6-11.2.0.4.jar使用 java 代码和驱动程序 ojdbc6-11.2.0.4.jar 执行的请求

is there anything wrong in my sql?我的 sql 有什么问题吗?

CREATE TABLE EMPLOYEE ( name_id varchar(255) PRIMARY KEY, modified_at TIMESTAMP, created_at TIMESTAMP );
 CREATE TABLE EMPLOYEE ( name_id varchar(255), modified_at TIMESTAMP, created_at TIMESTAMP, CONSTRAINT EMPLOYEE UNIQUE (name_id) );

is there anything wrong in my sql?我的 sql 有什么问题吗?

No, it works fine db<>fiddle .不,它工作正常db<>fiddle

The only two things you could change are to:您可以更改的唯一两件事是:

  • use VARCHAR2 and not VARCHAR .使用VARCHAR2而不是VARCHAR
  • name the constraint something different to the name of the table.将约束命名为与表名不同的名称。
CREATE TABLE EMPLOYEE (
    name_id     VARCHAR2(255),
    modified_at TIMESTAMP,
    created_at  TIMESTAMP,
    CONSTRAINT EMPLOYEE__name_id__u UNIQUE (name_id)
);

The request where executed using java code and the driver ojdbc6-11.2.0.4.jar使用 java 代码和驱动程序 ojdbc6-11.2.0.4.jar 执行的请求

Remove the semi-colon at the end if you are running the statement via JDBC.如果您通过 JDBC 运行该语句,请删除末尾的分号。 A semi-colon is a statement terminator in SQL/Plus (and SQL developer) but is not necessary (and is a syntax error) when you are using JDBC and similar (when you will only ever pass a single statement and so the terminator is unnecessary).分号是 SQL/Plus(和 SQL 开发人员)中的语句终止符,但当您使用 JDBC 和类似内容时(当您只传递一条语句,因此终止符是不必要)。

Instead of the inline pk declaration you can use something like this:代替内联 pk 声明,您可以使用如下内容:

CREATE TABLE EMPLOYEE (
   name_id varchar(255) PRIMARY KEY,
   modified_at TIMESTAMP,
   created_at TIMESTAMP
)
ALTER TABLE EMPLOYEE
ADD CONSTRAINT employee_pk PRIMARY KEY (name_id);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在使用oracle 10g创建表,但在查询中显示“ ORA-00922:缺少或无效的选项” - Im using oracle 10g to create table but it is showing “ORA-00922: missing or invalid option” and in the query ORA-00922:在oracle中执行“set long 100000”语句时缺少或无效选项 - ORA-00922: missing or invalid option when execute “set long 100000” statement in oracle java.sql.SQLSyntaxErrorException:ORA-00922:缺少或无效的选项 - java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option Apache NiFi无法使用ojdbc6.jar或ojdbc8.jar连接到Oracle 12c - Apache NiFi not able to connect to Oracle 12c using ojdbc6.jar or ojdbc8.jar 使用Oracle 12c和ojdbc7 / ojdbc8驱动程序的无效字符 - Invalid characters using Oracle 12c and ojdbc7 / ojdbc8 driver 使用ojdbc14驱动程序的Java中的Oracle数据库连接问题 - Oracle database connectivity issue in java using ojdbc14 driver Oracle 10.2.0.4.0 和 ojdbc11-21.1.0.0.jar || 获取JDBC连接失败; 嵌套异常是 ja │ │ ORA-01882: timezone region not found - Oracle 10.2.0.4.0 and ojdbc11-21.1.0.0.jar || Failed to obtain JDBC Connection; nested exception is ja │ │ ORA-01882: timezone region not found 无法通过OJDBC和Oracle DB执行SQL查询(但可以完全使用posgtres JDBC和Postgres DB) - cannot exexute SQL query wirh OJDBC and Oracle DB (but full working with posgtres JDBC and Postgres DB) 可能吗? 1)连接到Oracle 8i w / ojdbc5或ojdbc6 2)多个ojdbc jar - Either possible? 1) Connection to Oracle 8i w/ ojdbc5 or ojdbc6 2) Multiple ojdbc jars 使用ojdbc6驱动程序通过jdbc连接到Oracle 8i数据库时出错 - Error when connecting via jdbc to Oracle 8i database using ojdbc6 driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM