为什么 Oracle 认为我缺少右括号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/706503/
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
Why does Oracle think I'm missing a right parenthesis?
提问by Jason Cohen
In Oracle 10i, I'm running the following command:
在 Oracle 10i 中,我正在运行以下命令:
ALTER TABLE jnrvwchnglst ADD
( jnrvwchnglst_userid NUMBER(10) NOT NULL DEFAULT 1 )
Yes jnrvwchnglst
is an existing table and no jnrvwchnglst_userid
is not an existing column.
Yesjnrvwchnglst
是现有表, nojnrvwchnglst_userid
不是现有列。
The Oracle error message is:
Oracle 错误消息是:
ORA-00907: missing right parenthesis
What's wrong with this query and why does Oracle think I'm missing a parenthesis?
此查询有什么问题,为什么 Oracle 认为我缺少括号?
回答by Quassnoi
ALTER TABLE jnrvwchnglst ADD
( jnrvwchnglst_userid NUMBER(10) DEFAULT 1 NOT NULL )
回答by user1172173
"(NOT) NULL" must be the last statement in the "ALTER" syntactically when present, so when Oracle saw that - and that the next char (your "DEFAULT" stmt) wasn't the expected terminating right ")", threw the error.
“(NOT) NULL”在语法上必须是“ALTER”中存在的最后一条语句,因此当 Oracle 看到-并且下一个字符(您的“DEFAULT”stmt)不是预期的终止权“)”时,抛出错误。
回答by JasonRShaver
I have had this issue before where you can't add a column AND set the default/constraints in the same statement. The 'missing right parenthesis' is a red-herring. Oracle loves to use that error for cases that are unrelated to parenthesis (My guess is that their parsing logic falls through to 00907).
我之前遇到过这个问题,您无法在同一语句中添加列并设置默认值/约束。'缺少右括号'是一个红鲱鱼。Oracle 喜欢在与括号无关的情况下使用该错误(我的猜测是他们的解析逻辑落入了 00907)。
Try
尝试
ALTER TABLE jnrvwchnglst ADD ( nrvwchnglst_userid NUMBER(10) );
ALTER TABLE jnrvwchnglst ALTER ( nrvwchnglst_userid SET DEFAULT 1 );
UPDATE jnrvwchnglst SET nrvwchnglst_userid = 1 WHERE nrvwchnglst_userid IS NULL;
ALTER TABLE jnrvwchnglst ALTER ( nrvwchnglst_userid SET NOT NULL );