I am using Oracle 10 G, I want to decrease a column size from 30 to 20 characters.
Table name is member
, column is member_name
, it's a varchar2(30)
data type.
My question: is there any query to do it? If so, what is it?
I am using Oracle 10 G, I want to decrease a column size from 30 to 20 characters.
Table name is member
, column is member_name
, it's a varchar2(30)
data type.
My question: is there any query to do it? If so, what is it?
You can alter the lengths of string columns in place. But you get an error if existing values are too big. So, just shorten the column first:
update t
set col = substr(col, 1, 20)
where length(col) > 20;
Then:
alter table t modify x varchar2(20)
Here is a db<>fiddle.
I strongly recommend this approach because it is compatible with existing constraints and indexes.
You can not directly decrease the size of the VARCHAR2
column if it has some data.
You need to
queries should be as follows:
alter table member add member_name_new varchar2(20);
update member set member_name_new = member_name;
alter table member drop column member_name;
alter table member rename column member_name_new to member_name;