oracle SQL 错误:ORA-00907:缺少右括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8376662/
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
SQL Error: ORA-00907: missing right parenthesis
提问by Jatinder Singh
I am using Oracle SQL developer to create a basic table with the following command:
我正在使用 Oracle SQL 开发人员通过以下命令创建一个基本表:
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.
我有一种感觉,这与 TO_DATE 有关,还是因为我还没有创建我的飞机表所以飞机_no 丢失了?有哪位大神帮忙看看吗,谢谢。
回答by ziggy
There is no type called TO_DATE. To_DATE is used to convert a string to a date.
没有名为 TO_DATE 的类型。To_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
从表中选择数据时可以使用 to_date。例如
Select to_date(flight_date, 'yyyy/mm/dd') from chartered_flight;
回答by a1ex07
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.
要指定外键约束,您应该使用内联customer_id [type] REFERENCES [master_table_name]([master_column_name])
或外联 语法:在此处, CONSTRAINT [constraint_name] FOREIGN KEY(customer_id) REFERENCES [master_table_name]([master_column_name])
查看更多示例。此外,在外键列上添加索引通常是有意义的。
For flight_time you probably need to use INTERVAL DAY TO SECOND
type
对于 flight_time,您可能需要使用INTERVAL DAY TO SECOND
类型
回答by mannedear
ALTER TABLE EMPLOYEE_DETAILS ADD ( EMPLOYEE_ID NUMBER(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:
以上 ALTER 语句导致以下错误。
错误报告:
SQL 错误:ORA-00907:缺少右括号
00907. 00000 - “缺少右括号”
*原因:
*操作:
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), );
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
谢谢,
曼