SQL 错误:ORA-00907:缺少右括号
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有名为 TO_DATE 的类型。 To_DATE 用于将字符串转换为日期。
因此创建语句应该类似于
You can use to_date when select data from the table。例如
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
You can use to_date when selecting data from the table. For example
要指定外键约束,您应该使用内联
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上面的 ALTER 语句导致了以下错误。
错误报告:
SQL 错误:ORA-00907:缺少右括号
00907. 00000 - “缺少右括号”
*原因:
*行动:
我如何纠正自己,这是正确的。
解决方案:第二列的名称中有空格导致此错误。
谢谢,
曼内
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.
Solution: There is a space in the name of second column which caused this error.
Thanks,
Manne