Reputation: 83081
In Oracle 10i, I'm running the following command:
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.
The Oracle error message is:
ORA-00907: missing right parenthesis
What's wrong with this query and why does Oracle think I'm missing a parenthesis?
Upvotes: 11
Views: 10963
Reputation: 945
"(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.
Upvotes: 4
Reputation: 4394
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).
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 );
Upvotes: 0
Reputation: 425763
ALTER TABLE jnrvwchnglst ADD
( jnrvwchnglst_userid NUMBER(10) DEFAULT 1 NOT NULL )
Upvotes: 21