执行CREATE TABLE脚本触发ORA-00907错误:缺少右括号问题求助
Alright, let's figure out why you're hitting that ORA-00907 "missing right parenthesis" error and fix your ATTRACTION_MH table script — it's a mix of simple typos and syntax gaps tripping up Oracle's parser.
Key Error Causes
- Missing closing parenthesis (the immediate trigger for ORA-00907)
Your script cuts off mid-definition at"AllocatedTime" NUMBER(3) NOTNULL ENABLE— there's no closing)to wrap up all column definitions, nor a terminating;to end the statement. This is the first thing Oracle flags. - Syntax typo:
NOTNULLshould beNOT NULL
You merged the two keywords for theAllocatedTimecolumn. Oracle requires a space betweenNOTandNULLto recognize the constraint correctly. - Non-standard
VARCHARusage
You usedVARCHAR(15)for theCategorycolumn. While Oracle treatsVARCHARas an alias forVARCHAR2, it's best practice to useVARCHAR2consistently to avoid compatibility quirks. - Redundant
NOT NULLon primary key column
APRIMARY KEYconstraint already enforcesNOT NULL, so including both onCityNameis unnecessary (though not a breaking error).
Corrected Scripts
Here's the fixed, minimal version that will run without errors:
CREATE TABLE "ATTRACTION_MH"( "AttractionNo" NUMBER(11) NOT NULL ENABLE, "CityName" VARCHAR2(25) PRIMARY KEY ENABLE, -- PK implies NOT NULL, so we can omit that "AttractionName" VARCHAR2(25) NOT NULL ENABLE, "Category" VARCHAR2(15) NOT NULL ENABLE, -- Switched VARCHAR to VARCHAR2 "AllocatedTime" NUMBER(3) NOT NULL ENABLE -- Fixed NOTNULL to NOT NULL ); -- Added closing parenthesis and terminating semicolon
If you prefer explicit constraint names (easier for debugging later), use this more maintainable version:
CREATE TABLE "ATTRACTION_MH"( "AttractionNo" NUMBER(11) NOT NULL ENABLE, "CityName" VARCHAR2(25) NOT NULL ENABLE, "AttractionName" VARCHAR2(25) NOT NULL ENABLE, "Category" VARCHAR2(15) NOT NULL ENABLE, "AllocatedTime" NUMBER(3) NOT NULL ENABLE, CONSTRAINT PK_ATTRACTION_MH_CITYNAME PRIMARY KEY ("CityName") ENABLE );
内容的提问来源于stack exchange,提问作者Matt
相关产品推荐
相关产品推荐

