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 ?
it is not possible to decrease the size of column. same table it is not possible.
In generic terms, you use the ALTER TABLE command followed by the table name, then the MODIFY command followed by the column name and new type and size. Here is an example: ALTER TABLE tablename MODIFY columnname VARCHAR(20) ; The maximum width of the column is determined by the number in parentheses.
SQL - Modify Column Data Type and SizeALTER TABLE Employee ALTER COLUMN FirstName VARCHAR(50); The following will change the size in the Oracle database. ALTER TABLE Employee MODIFY (FirstName VARCHAR2(50)); The following will change the size in the PostgreSQL database.
In this case, you need to use ALTER TABLE statement to increase column size. ALTER TABLE table_name MODIFY column_name varchar(new_length); In the above command, you need to specify table_name whose column you want to modify, column_name of column whose length you want to change, and new_length, new size number.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With