Why does Oracle think I'm missing a right parenthesis?

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?

Answers


ALTER TABLE jnrvwchnglst ADD
     ( jnrvwchnglst_userid NUMBER(10) DEFAULT 1  NOT NULL )

"(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.


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 );

Need Your Help

json_encode function: special characters

php json

Elements of an array containing special characters are converted to empty strings when encoding the array with json_encode:

How do you implement the equivalent of SQL IN() using .net

c# .net sql sql-server vb.net

In .net (c# or vb) expressions, how would you implement SQL's handy IN() functionality?