Alter Table Modify Column Oracle

MODIFY keyword with ALTER is used to modify the database of the Column in a table. It also helps to decide the nullability of a column.

Alter Table Modify Column OracleSyntax

ALTER TABLE table_name
MODIFY column_name Datatype;
  • column_name is the name of the column for which we need to change the datatype.
  • Datatype above describes the datatype to which we want to change the table.
  • We cannot modify the column that already contains values.

Alter Table Modify Column Oracle Example

Referring to the current schema of Stu table below:

Alter Table Modify Column Oracle Example

We can see that for lname the current Datatype is Varchar(with size 20). Now, we want to change this Datatype from Varchar to Char with size 20.

Alter table Stu
modify lname char(20);

Output

oracle alter table modify column default value example

and we got the current schema as:

alter table modify column oracle with example

Example: Oracle Modify the column as NOT NULL

We can also describe the column lname as NOT NULL using MODIFY:

Firstly we need to give specific values to all NOT NULL values. 

update stu
Set lname='not defined'
where lname is null;

Output:

Oracle Modify the column as NOT NULL example

Now we can Modify lname column as NOT NULL:

Alter table Stu
modify lname NOT NULL;

Output:

Oracle Modify the column as NOT NULL example

Now you can find the schema that is shown below:

Oracle Modify the column example