ALTER TABLE ... MODIFY changes a column’s data type, length, or precision in Oracle databases.
Use ALTER TABLE … MODIFY when an existing column’s data range has outgrown its current definition or its data type no longer matches business rules. The command updates the data dictionary instantly and preserves data when possible.
The minimal form is:ALTER TABLE table_name MODIFY (column_name new_data_type [constraints]);
Add constraints or DEFAULT as needed.The column must not be part of a PRIMARY KEY when reducing size.
Expanding is safe and instantaneous.Example:ALTER TABLE Customers MODIFY (email VARCHAR2(150));
Increase precision with:ALTER TABLE Orders MODIFY (total_amount NUMBER(12,2));
Oracle rewrites metadata without rewriting every row.
You must first create a new column, populate it with TO_DATE conversions, verify, then drop the old column:ALTER TABLE Orders ADD (order_date_new DATE);UPDATE Orders SET order_date_new = TO_DATE(order_date,'YYYY-MM-DD');ALTER TABLE Orders DROP COLUMN order_date;ALTER TABLE Orders RENAME COLUMN order_date_new TO order_date;
Back up the table, verify constraints, and apply changes in off-peak hours.Use online redefinition for very large tables.
You cannot directly UNDO a MODIFY. Restore from backup or apply another ALTER TABLE to return to the original definition, then reconvert data.
DESC Products;
ALTER TABLE Products MODIFY (price NUMBER(10,2));
SELECT column_name,data_type,data_precision,data_scale FROM user_tab_columns WHERE table_name='PRODUCTS' AND column_name='PRICE';
.
Expanding length or precision incurs only a brief metadata lock. Conversions that rewrite data may lock rows until completion.
Yes, but Oracle rewrites each partition. Consider online redefinition for large datasets.
No. Indexes remain valid if the key length stays within limits. Rebuild only if you shrink a column used in an index.