Reputation:
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?
Upvotes: 0
Views: 1412
Reputation: 1269503
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.
Upvotes: 1
Reputation: 35900
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;
Upvotes: 0