views:

495

answers:

2

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?

+4  A: 
ALTER TABLE jnrvwchnglst ADD
     ( jnrvwchnglst_userid NUMBER(10) DEFAULT 1  NOT NULL )
Quassnoi
Thanks! I've confirmed this works.
Jason Cohen
+1  A: 

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 );
JasonRShaver
Darn it =) Or it could just be an order of operations issue. bah =)
JasonRShaver
That's true with e.g. TIMESTAMP. However Quassnoi's code does work. Thanks!
Jason Cohen