views:

239

answers:

3

I'm trying to ALTER a table by adding a new CLOB column (on Oracle 10), but it's failing. Giving me an ORA-01735 error. Problem is I can't find out what in particular is wrong with my query by googling around so I figured I'd ask here just in case.

Anyways my query is:

 ALTER TABLE "MYSCHEMA"."MYTABLE" ADD "ACOLUMN" CLOB(2048);

And get the following error:

SQL Error: ORA-01735: invalid ALTER TABLE option
01735. 00000 -  "invalid ALTER TABLE option"

Any ideas?

Thanks.

+4  A: 

You can't specify a size for CLOB (use VARCHAR if you want to specify a size):

SQL> alter table t add ("ACOLUMN" CLOB(2048));

alter table t add ("ACOLUMN" CLOB(2048))

ORA-00907: missing right parenthesis

SQL> alter table t add ("ACOLUMN" CLOB);

Table altered
Vincent Malgrat
Yeah I was getting that missing right parenthesis error after trying the ADD("ACOLUMN" CLOB(2049)) syntax. I Guess I might use VARCHAR instead, thanks
Robert Gould
+1  A: 
alter table t add a_column clob;
alter table t add a_column_with_max_size varchar2(1234); --max 4000
Michal Pravda
Thanks for reminding me about the 4k limit on Varchar2! Almost forgot it.
Robert Gould
+1  A: 

If you never want more than 2048 characters in that column, don't use a CLOB, use VARCHAR2(2048). VARCHAR2 is good for up to 4000 characters; only use CLOB if you may need more than that.

Tony Andrews
I'm mentally debating the issue in my head right now... do I need a CLOB or VARCHAR2... VARCHAR2 seems good enough, but one day it'll likely change as everything does, and then it'll become a CLOB... mmm
Robert Gould
What is the purpose of the column? If it is to hold an arbitrary amount of text that can't be edited down, like the contents of a letter or detailed instructions then go for CLOB; if it is just somewhere for the user to record a few notes about the record and they can reasonably be expected to always edit it down to no more than 4000 chars, use VARCHAR2.
Tony Andrews