How to Change Column Type in Oracle

Galaxy Glossary

How do I change a column's data type in Oracle?

ALTER TABLE ... MODIFY changes a column’s data type, length, or precision in Oracle databases.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why use ALTER TABLE … MODIFY to change column type?

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.

What is the basic syntax?

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.

How do I expand VARCHAR2 length?

Expanding is safe and instantaneous.Example:
ALTER TABLE Customers MODIFY (email VARCHAR2(150));

How do I change NUMBER precision?

Increase precision with:
ALTER TABLE Orders MODIFY (total_amount NUMBER(12,2));
Oracle rewrites metadata without rewriting every row.

How do I convert VARCHAR2 to DATE?

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;

Best practices for zero-downtime changes?

Back up the table, verify constraints, and apply changes in off-peak hours.Use online redefinition for very large tables.

Can I revert a type change?

You cannot directly UNDO a MODIFY. Restore from backup or apply another ALTER TABLE to return to the original definition, then reconvert data.

Step-by-step e-commerce example

1. Check current definition

DESC Products;

2. Alter column

ALTER TABLE Products MODIFY (price NUMBER(10,2));

3. Verify

SELECT column_name,data_type,data_precision,data_scale FROM user_tab_columns WHERE table_name='PRODUCTS' AND column_name='PRICE';

.

Why How to Change Column Type in Oracle is important

How to Change Column Type in Oracle Example Usage


--Change Orders.total_amount from NUMBER(8,2) to NUMBER(12,2)
ALTER TABLE Orders
  MODIFY (total_amount NUMBER(12,2));

How to Change Column Type in Oracle Syntax


ALTER TABLE table_name
  MODIFY (
    column_name new_data_type [DEFAULT expr]
               [NOT NULL | NULL]
               [CHECK (condition)]
               [COLUMN FORMAT format_only]
  );
--E-commerce examples
--1. Expand email length
ALTER TABLE Customers
  MODIFY (email VARCHAR2(150));
--2. Increase monetary precision
ALTER TABLE Orders
  MODIFY (total_amount NUMBER(12,2));
--3. Shrink VARCHAR2 (requires empty or validated data)
ALTER TABLE Products
  MODIFY (name VARCHAR2(80));

Common Mistakes

Frequently Asked Questions (FAQs)

Does ALTER TABLE … MODIFY lock the table?

Expanding length or precision incurs only a brief metadata lock. Conversions that rewrite data may lock rows until completion.

Can I change data type in a partitioned table?

Yes, but Oracle rewrites each partition. Consider online redefinition for large datasets.

Will indexes rebuild automatically?

No. Indexes remain valid if the key length stays within limits. Rebuild only if you shrink a column used in an index.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.