SQL 错误:ORA-00907:缺少右括号

发布于 2024-12-19 23:01:55 字数 1112 浏览 2 评论 0原文

我正在使用 Oracle SQL Developer 创建一个基本表,命令如下:

CREATE TABLE chartered_flight(
   flight_no NUMBER(4) PRIMARY KEY
   , customer_id FOREIGN KEY
   , aircraft_no FOREIGN KEY
   , flight_type VARCHAR2 (12)
   , flight_date DATE NOT NULL
   , flight_time TO_DATE 'HH:MI' NOT NULL
   , takeoff_at CHAR (3) NOT NULL
   , destination CHAR (3) NOT NULL
)

缺少的右括号在哪里?或者我使用的语法不正确。

我进行了以下更改:

CREATE TABLE chartered flight(
   flight_no NUMBER(4) PRIMARY KEY
   , customer_id NUMBER(6) REFERENCES [customer]([customer_id])
   , aircraft_no NUMBER(4) REFERENCES [aircraft]([aircraft_no])
   , flight_type VARCHAR2 (12)
   , flight_date DATE NOT NULL
   , flight_time INTERVAL DAY TO SECOND NOT NULL
   , takeoff_at CHAR (3) NOT NULL
   , destination CHAR (3) NOT NULL)

现在我收到此错误:

Error at Command Line:1 Column:23
Error report:
SQL Error: ORA-00922: missing or invalid option
00922. 00000 -  "missing or invalid option"
*Cause:    
*Action:

我感觉这与 TO_DATE 有关,或者是因为我尚未创建飞机表,所以缺少aircraft_no?有人可以帮忙吗,谢谢。

I am using Oracle SQL developer to create a basic table with the following command:

CREATE TABLE chartered_flight(
   flight_no NUMBER(4) PRIMARY KEY
   , customer_id FOREIGN KEY
   , aircraft_no FOREIGN KEY
   , flight_type VARCHAR2 (12)
   , flight_date DATE NOT NULL
   , flight_time TO_DATE 'HH:MI' NOT NULL
   , takeoff_at CHAR (3) NOT NULL
   , destination CHAR (3) NOT NULL
)

Where is the missing right parenthesis? Or is the syntax that I have used incorrect.

I have made the following changes:

CREATE TABLE chartered flight(
   flight_no NUMBER(4) PRIMARY KEY
   , customer_id NUMBER(6) REFERENCES [customer]([customer_id])
   , aircraft_no NUMBER(4) REFERENCES [aircraft]([aircraft_no])
   , flight_type VARCHAR2 (12)
   , flight_date DATE NOT NULL
   , flight_time INTERVAL DAY TO SECOND NOT NULL
   , takeoff_at CHAR (3) NOT NULL
   , destination CHAR (3) NOT NULL)

Now I get this error:

Error at Command Line:1 Column:23
Error report:
SQL Error: ORA-00922: missing or invalid option
00922. 00000 -  "missing or invalid option"
*Cause:    
*Action:

I have a feeling it is something to do with TO_DATE or is it because I have not created my aircraft table yet so aircraft_no is missing? Can some one please help, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£噩梦荏苒 2024-12-26 23:01:55

没有名为 TO_DATE 的类型。 To_DATE 用于将字符串转换为日期。

因此创建语句应该类似于

CREATE TABLE chartered_flight(
    flight_no NUMBER(4) PRIMARY KEY, 
    customer_id FOREIGN KEY, 
    aircraft_no FOREIGN KEY, 
    flight_type VARCHAR2 (12), 
    flight_date DATE NOT NULL,
    flight_time VARCHAR(4) NOT NULL, 
    takeoff_at CHAR (3) NOT NULL, 
    destination CHAR (3) NOT NULL)

You can use to_date when select data from the table。例如

Select to_date(flight_date, 'yyyy/mm/dd') from chartered_flight;

There is no type called TO_DATE. To_DATE is used to convert a string to a date.

So the create statement should be something like

CREATE TABLE chartered_flight(
    flight_no NUMBER(4) PRIMARY KEY, 
    customer_id FOREIGN KEY, 
    aircraft_no FOREIGN KEY, 
    flight_type VARCHAR2 (12), 
    flight_date DATE NOT NULL,
    flight_time VARCHAR(4) NOT NULL, 
    takeoff_at CHAR (3) NOT NULL, 
    destination CHAR (3) NOT NULL)

You can use to_date when selecting data from the table. For example

Select to_date(flight_date, 'yyyy/mm/dd') from chartered_flight;
寂寞花火° 2024-12-26 23:01:55

要指定外键约束,您应该使用内联 customer_id [type] REFERENCES [master_table_name]([master_column_name]) 或外行语法:, CONSTRAINT [constraint_name] FOREIGN KEY(customer_id)参考 [master_table_name]([master_column_name]) 查看更多示例 此处。此外,在外键列上添加索引通常是有意义的。

对于flight_time,您可能需要使用INTERVAL DAY TO SECOND类型

To specify foreign key constraint, you should either use inline customer_id [type] REFERENCES [master_table_name]([master_column_name]) or out of line syntax : , CONSTRAINT [constraint_name] FOREIGN KEY(customer_id) REFERENCES [master_table_name]([master_column_name]) See more example here. Also, it usually makes sense to add indexes on foreign key columns.

For flight_time you probably need to use INTERVAL DAY TO SECOND type

千笙结 2024-12-26 23:01:55

更改表 EMPLOYEE_DETAILS 添加 (
EMPLOYEE_ID 号(10),
员工姓名 VARCHAR2(100),
);

上面的 ALTER 语句导致了以下错误。
错误报告:
SQL 错误:ORA-00907:缺少右括号
00907. 00000 - “缺少右括号”
*原因:
*行动:

我如何纠正自己,这是正确的。

更改表 EMPLOYEE_DETAILS 添加 (
EMPLOYEE_ID 号(10),
EMPLOYEE_NAME VARCHAR2(100),
);

解决方案:第二列的名称中有空格导致此错误。

谢谢,
曼内

ALTER TABLE EMPLOYEE_DETAILS ADD (
EMPLOYEE_ID NUMBER(10),
EMPLOYEE NAME VARCHAR2(100),
);

Above ALTER statement caused the below error.
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:

How ever I have rectified my self and here is the correct one.

ALTER TABLE EMPLOYEE_DETAILS ADD (
EMPLOYEE_ID NUMBER(10),
EMPLOYEE_NAME VARCHAR2(100),
);

Solution: There is a space in the name of second column which caused this error.

Thanks,
Manne

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文