Changing the Data Type of a Column
The following ALTER TABLE
statement changes the data type of the emp.ename column to CHAR
:
SQL> CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
2 ENAME VARCHAR2(10),
3 JOB VARCHAR2(9),
4 SAL NUMBER(7, 2),
5 DEPTNO NUMBER(2));
Table created.
SQL>
SQL>
SQL> ALTER TABLE emp MODIFY ename CHAR(15);
Table altered.
SQL>
If the table is empty or the column contains null values, you can change the column to any data type.
Otherwise, you can change the data type of a column only to a compatible data type.
For example, you can change a VARCHAR2
to CHAR
but you cannot change a DATE
to a NUMBER
.
Home »
Oracle »
Table »
Oracle »
Table »
Column:
- Adding a Column
- Adding a Virtual Column
- Changing the Size of a Column
- Changing the Precision of a Numeric Column
- Changing the Data Type of a Column
- Changing the Default Value of a Column
- Dropping a Column
Related: