alter the size of column in table containing data

SqlOracle

Sql Problem Overview


> Possible Duplicate:
> How to make a varchar2 field shorter in Oracle?

In Oracle(9i and above)

 Alter table employee  
 MODIFY ename varchar2(10);

I want to alter the column ename of table employee from varchar2(30) to varchar2(10)

  • Case1 : if the table has data having ename column containing values which are of length less than 10 char(i mean it can fit in varchar2(10) comfortably) - is this allowed by oracle ?

  • Case 2: if the table has data having ename column containing values which are of length greater than 10 char(i mean it can not fit in varchar2(10)) - is this not allowed by oracle ?

Sql Solutions


Solution 1 - Sql

Case 1 : Yes, this works fine.

Case 2 : This will fail with the error ORA-01441 : cannot decrease column length because some value is too big.

Share and enjoy.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlowLatencyView Question on Stackoverflow
Solution 1 - SqlBob Jarvis - Слава УкраїніView Answer on Stackoverflow