0

Can we decrease a size of a column? Suppose there is table A having column size 10. After inserting the data in the table, I want to reduce the size of the column. Can we reduce it?

Create table A 
(Emp varchar2(10));

Insert into A values ('Ana');

Alter table A modify (varchar2(5));
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • 1
    Does this answer your question? [how to modify the size of a column](https://stackoverflow.com/questions/39785471/how-to-modify-the-size-of-a-column) – Koen Lostrie Jan 06 '23 at 12:02

1 Answers1

0

Yes you can. An error will be thrown if the existing values have a larger size than the new datatype. See below.

koen>create table things (name VARCHAR2(100));

Table THINGS created.

koen>insert into things(name) values ('Car');

1 row inserted.

koen>alter table things modify  name VARCHAR2(5);

Table THINGS altered.

koen>alter table things modify  name VARCHAR2(2);

Error starting at line : 1 in command -
alter table things modify  name VARCHAR2(2)
Error report -
ORA-01441: cannot decrease column length because some value is too big
01441. 00000 -  "cannot decrease column length because some value is too big"
*Cause:    
*Action:
koen>

Koen Lostrie
  • 14,938
  • 2
  • 13
  • 19